Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Remove padding from button

Tags:

android

How can I remove the padding from a Button view? At least I need to have equal padding on all sides no matter what.

I have this

<Button
   style="@style/btnStart"
   android:text="@string/start" />

And this style

<style name="btnStart" parent="@android:style/Widget.Button">
    <item name="android:background">@drawable/selector_start_button</item>
    <item name="android:textColor">@drawable/selector_start_button_text</item>
    <item name="android:layout_width">wrap_content</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:textSize">24sp</item>                       
</style>

And this drawable selector_start_button.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true">
    <shape>
        <solid android:color="@color/start_button" />
        <stroke android:color="@color/start_button" android:width="1dp" />
        <padding
        android:left="0dp"
        android:top="0dp"
        android:right="0dp"
        android:bottom="0dp" />            
    </shape>            
    </item>

    <item>
        <shape>
            <solid android:color="#00000000" />
            <stroke android:color="@color/start_button" android:width="1dp" />            
            <padding
            android:left="0dp"
            android:top="0dp"
            android:right="0dp"
            android:bottom="0dp" />
        </shape>
    </item>
</selector>

But I still get this

button with unwanted padding

like image 455
PFort Avatar asked Aug 16 '26 08:08

PFort


1 Answers

Maybe your button is inheriting a minHeight. Try overriding it:

<Button
    ...
    android:minHeight="0dp"
    .../>
like image 195
user291701 Avatar answered Aug 19 '26 01:08

user291701



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!