Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I reduce the inner padding around the text within an Android button object?

Example buttons

So, at the moment I have a button which looks like the first image above. How do I reduce the padding around the text inside the button itself (To look more like the second image)?

Layout width and height is set as:

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

The custom style shape has parameters"

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

With the rest just being color attributes and radii values.

Just to make it clear, I want the frame of the button to hug the "Login" text closer.

All help and feedback is greatly appreciated. Thanks.

like image 772
Imran NZ Avatar asked May 06 '13 07:05

Imran NZ


People also ask

How do you remove button padding?

You can remove the padding around the button by using setting the minWidth and minHeight to 0.

How to change the Button style in android?

To change the default Button style of the application we can use the android:buttonStyle attribute in the AppTheme style inside the styles. xml. This sets default colored button to all.

How to style Button in Android studio?

To add a button, that has an Android style all you need to do is to drag and drop a button from the Palette to your layout. For most versions that would mean a grey button with all corners at 2dp roundness. Check our blog, if you need to learn more about using Android Studio Layout Editor.

What is includeFontPadding?

You can use android:includeFontPadding="false" to get rid of the default padding in a TextView . Android docs say this about the attribute: Leave enough room for ascenders and descenders instead of using the font ascent and descent strictly.


1 Answers

It took me forever to find this but the "padding" around the text in a button isn't really padding at all. The default Widget.Button style includes a minHeight property. Changing minHeight on the button will allow you to adjust 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> 
like image 75
Steven Avatar answered Oct 14 '22 16:10

Steven