[TIMOB-9277] Android: Cannot add label to a button. Works on iOS
GitHub Issue | n/a |
Type | Bug |
Priority | Low |
Status | Closed |
Resolution | Cannot Reproduce |
Resolution Date | 2020-01-09T22:09:00.000+0000 |
Affected Version/s | Release 2.0.1, Release 3.1.0 |
Fix Version/s | n/a |
Components | Android |
Labels | SupportTeam, api, parity |
Reporter | Varun Joshi |
Assignee | Unknown |
Created | 2012-05-25T08:05:03.000+0000 |
Updated | 2020-01-09T22:09:00.000+0000 |
Description
Problem
Please run the sample code below:
{noformat}
//create component instance
var self = Ti.UI.createWindow({
backgroundColor : '#ffffff',
navBarHidden : true,
exitOnClose : true
});
self.open();
var button = Ti.UI.createButton({
top: 10,
left: 50,
width: 200,
height: 100,
image: 'KS_nav_ui.png'
});
var label = Ti.UI.createLabel({
text: 'Hello World'
});
button.add(label);
self.add(button);
{noformat}
On Android, the above code does not display the label on the button. It works fine on iOS.
The desired effect should be the same as iOS where the button image is shown on the left (as shown in the screenshot) and label on the right.
Attachments
Yes on Android the Button widget is NOT a ViewGroup. What is the use case here of using a Label rather then just setting the "title" of the button? I don't think supporting child views in Buttons will be something we support on Android. Like Blain says there might be a better way to accomplish what you are trying to do.
We can use "\n" to break the line for the "title" of the button on Android and Mobile Web.
Issue still present in the following sdk versions - version 3.0.2, version 3.1.0. So the bug can be reproduced in the latest build.
This feature is necessary in cases where you want to position text or counters inside a button view. By having this you can make custom buttons. The title parameter on the button view doesn't allow much customization, specially regarding the positioning of the text.