| java.lang.Object | ||
| ↳ | com.neomades.ui.View | |
| ↳ | com.neomades.ui.Button | |
A Button represents a button into screen in order to intercept
events (touch and keys).
Handling click events
A typical use of Button could be :
ClickListener clickListener = new ClickListener() {
public void onClick(View view) {
// do some stuff
}
};
Button myButton = new Button("Text of the button");
myButton.setClickListener(clickListener);
layout.addView(myButton);
By default, the following properties are applied to a new Button:
MATCH_PARENT.MATCH_CONTENT.HCENTER|VCENTER.
In Android, a Button is a android.widget.Button. It will
contain text. Use background methods (such as
setBackgroundImage(int)) to customize the visual aspect.
In iOS, a Button is a UIButton with style
UIButtonStyleRoundedRect. This default style will represent the
Button as a button with rounded corners. Using a customized
background will replace the default style (the default border and lines will
be hidden).
| XML Attributes | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Attribute Name | Related Method | Description | |||||||||
| contentAlignment | setContentAlignment(int) | A combination of alignment values (eg: TOP|LEFT) | |||||||||
| font | setFont(Font) | Font resource id: Res.font.FONT_XXXX | |||||||||
| text | setText(int) | Res.string.XXXX or a text | |||||||||
| textColor | setTextColor(Color) | #AARRGGBB or a color | |||||||||
| textSize | setTextSize(int) | a size in dp | |||||||||
|
[Expand]
Inherited XML Attributes | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
From class
com.neomades.ui.View
| |||||||||||
|
[Expand]
Inherited Constants | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
From interface
com.neomades.ui.Alignment
| |||||||||||
From interface
com.neomades.ui.StretchMode
| |||||||||||
| Public Constructors | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
|
Button()
Creates a button without text or image.
| |||||||||||
|
Button(String text)
Creates a button with text.
| |||||||||||
|
Button(int textId)
Creates a button with an ID representing a String.
| |||||||||||
| Public Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| int |
getContentAlignment()
Returns the current text alignment of the button
| ||||||||||
| String |
getText()
Returns the button's text.
| ||||||||||
| void |
setClickListener(ClickListener clickListener)
Sets a ClickListener to this button.
| ||||||||||
| void |
setContentAlignment(int alignment)
Sets the alignment of the text or icon in the button.
| ||||||||||
| void |
setFont(Font font)
Sets the button text font.
| ||||||||||
| void |
setText(String text)
Sets the text of the button
If the text parameter is null, no text is set. | ||||||||||
| void |
setText(int resId)
Sets the text of the button with an ID representing a String
| ||||||||||
| void |
setTextColor(Color textColor)
Sets the button text color.
| ||||||||||
| void |
setTextSize(int sizeInDp)
Sets the text size to a given value (in dp).
| ||||||||||
|
[Expand]
Inherited Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
From class
com.neomades.ui.View
| |||||||||||
From class
java.lang.Object
| |||||||||||
A combination of alignment values (eg: TOP|LEFT)
Creates a button without text or image.
For further information, see Default properties
Creates a button with text.
For further information, see Default properties
If the text parameter is null, no text is set.
| text | the text content of this button |
|---|
Creates a button with an ID representing a String.
For further information, see Default properties
| textId | the string id assigned to this button |
|---|
Returns the current text alignment of the button
AlignmentReturns the button's text. Returns an empty string ("") if there is no text.
Sets a ClickListener to this button.
When the button is clicked, the onClick()
method from ClickListener will be called, with the clicked button as
parameter.
| clickListener | The listener to set on the button (or null to remove the current listener) |
|---|
| CrossThreadException | if the method is called from outside the UI-Thread |
|---|
Sets the alignment of the text or icon in the button. The parameter is a
combination of values from Alignment
| alignment | The new alignment of the button's text |
|---|
| CrossThreadException | if the method is called from outside the UI-Thread |
|---|
Sets the button text font.
| font | new font for the text |
|---|
| CrossThreadException | if the method is called from outside the UI-Thread |
|---|---|
| NullPointerException | if the font parameter is null |
Sets the text of the button
If the text parameter is null, no text is set.
| text | the new button text |
|---|
| CrossThreadException | if the method is called from outside the UI-Thread |
|---|
Sets the text of the button with an ID representing a String
| resId | the string id assigned to this button |
|---|
| CrossThreadException | if the method is called from outside the UI-Thread |
|---|
Sets the button text color.
| textColor | new color for the text |
|---|
| CrossThreadException | if the method is called from outside the UI-Thread |
|---|---|
| NullPointerException | if the parameter is null |
Sets the text size to a given value (in dp).
| sizeInDp | size to set to the text |
|---|