android text not showing in button
Solution 1
I had this problem, I solved it by chaning the xml for the button from using tools: to android: for the text attribute. Example below (last line is the line thats changed):
<Button
android:id="@+id/btn_settings"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#F6F6F6"
tools:text="App Settings" />
becomes...
<Button
android:id="@+id/btn_settings"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#F6F6F6"
android:text="App Settings" />
Solution 2
try to replace android:text="@string/latestButtonString"
and put direct hardcode string here as,
android:text="hello"
or
try to replace this line in roundbutton.xml:
<android:shape="rectangle" android:padding="10dp">
with
<android:shape="rectangle" android:padding="3dp">
Solution 3
Can you please check by removing android:background="@drawable/roundbutton"
from your button attribute. If text shown fully, then you need to modify the @drawable/roundbutton"
there may be you have set fixed width
thus your text in button is not fully visible.
Solution 4
It seems that you have a paddingLeft
on your Button
. Can you check if this is present in your styles.xml
?
If it is in your styles.xml
, it is probably important for the theme of your app.
If you would just want to cancel it in that certain Button
, just put
android:paddingLeft="0dp"
Comments
-
spacemonkey almost 2 years
This happens very frequently to me when starting to work on android. The text within the button element is not showing fully. What can be wrong? I tried text direction, alignment, gravity but nothing works.
The code behind it:
<Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/textView1" android:layout_centerHorizontal="true" android:layout_marginTop="40dp" android:text="@string/latestButtonString" android:background="@drawable/roundbutton" />
Please help and much appreciated.
Update: This is the roundbutton.xml:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" android:padding="10dp"> <!-- you can use any color you want I used here gray color--> <solid android:color="#ABABAB"/> <corners android:bottomRightRadius="10dp" android:bottomLeftRadius="10dp" android:topLeftRadius="10dp" android:topRightRadius="10dp"/> </shape>