How do I reduce the inner padding around the text within an Android button object?
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>
In the Material Components Library, the MaterialButton
has a default style with insetBottom
and insetTop
with a value of 6dp
.
You can change them in the layout:
<com.google.android.material.button.MaterialButton
android:insetTop="0dp"
android:insetBottom="0dp"
../>
or in a style:
<style name="Button_no_insets" parent="Widget.MaterialComponents.Button"..>
<item name="android:insetTop">0dp</item>
<item name="android:insetBottom">0dp</item>
</style>
try this in your custom shape.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 change in your button's xml
android:layout_width="wrap_content"
android:layout_height="wrap_content"