"wrap_content" is not working in my button, it currently looks like this:
now want
____________
| | _____________
| aaaaaa | => | aaaaaaaaaaa |
|____________| -------------
and the xml for my buttons :
<Button
android:layout_gravity="center"
android:id="@+id/input_expend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:text="aaaaaaa"
android:background="@drawable/btn_01"/>
<Button
android:layout_gravity="center"
android:id="@+id/input_expend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:text="aaaaaaa"
android:background="@drawable/btn_02"/>
How can I solve this problem? Thanks!
To add actions to the action bar, create a new XML file in your project's res/menu/ directory. The app:showAsAction attribute specifies whether the action should be shown as a button on the app bar.
To set Android Button background color, we can assign android:backgroundTint XML attribute for Button in layout file with the required Color Value. To programmatically set or change Android Button background color, we may call pass the method Button.
Button
is a View
and the android:minHeight
attribute is set 48dip
default. You can set minHeight
lower than your actual text 'aaaaa' such as 1dp. Then wrap_content
will work. But I don't think this is recommended.
One solution is to add android:padding="@null"
to the button in your XML. This will override any existing padding being enforced.
There is also an issue I've come across where a button will not shrink smaller than the padding defined in the default button style. I highlighted this in my own question some time ago but haven't had an answer that resolves it yet.
Changing the background didn't work, as well as padding="@null".
I ended up using a TextView because my button was simple enough for it to suffice:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Join"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:padding="5dp"
android:textSize="@dimen/xsmall_text_size"
android:textColor="@drawable/button_text_selector"
android:background="@color/turquoise"
android:textStyle="bold"
android:onClick="buttonOnClick"
android:clickable="true"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With