How to reduce internal registration around the text in an Android button object?

Example buttons

So, at the moment I have a button that looks like the first image above. How to reduce the registration around the text inside the button itself (to look more like a second image)?

The width and height of the layout are set as:

android:layout_width="match_parent" android:layout_height="wrap_content" 

Custom style form has options "

 <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" android:padding="10dp"> 

The rest are simply color attributes and radius values.

Just to make it clear, I want the button frame to hug the text β€œSign In”.

All help and feedback is appreciated. Thank.

+47
java android user-interface xml mobile
May 6 '13 at 7:43
source share
4 answers

It took me a long time to find this, but the "indents" around the text in the button are not filled at all. By default, the Widget.Button style includes the minHeight property. Changing minHeight on the button will allow you to adjust the padding as expected.

 <Button android:id="@+id/header" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/test" android:textColor="@color/black" android:minHeight="40dip"/> <style name="Widget.Holo.Button" parent="Widget.Button"> <item name="android:background">@android:drawable/btn_default_holo_dark</item> <item name="android:textAppearance">?android:attr/textAppearanceMedium</item> <item name="android:textColor">@android:color/primary_text_holo_dark</item> <item name="android:minHeight">48dip</item> <item name="android:minWidth">64dip</item> </style> 
+131
Oct 10 '13 at 16:01
source share

try this in your custom.xml file.

 <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" android:paddingLeft="10dp" android:paddingRight="10dp" android:paddingTop="1dp" android:padding="1dp"> 

also you can make changes to your xml button

 android:layout_width="wrap_content" android:layout_height="wrap_content" 
+4
May 6 '13 at 11:24
source share

This helped me - stack overflow.site/questions/114873 / ... (author - @StinePike) From the answer - Add android:includeFontPadding="false"

+4
Oct 14 '15 at 11:13
source share

If you want to reduce the top and bottom fill, use this:

  android:paddingTop="2dp" android:paddingBottom="2dp" 
+1
May 6 '13 at 8:10
source share



All Articles