2

I'm trying to make mu custom button with no padding. For that purpose I created following selector:

 <?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="#33b5e5"/>
            <corners
                android:radius="1dp" />
            <padding
                android:left="0dp"
                android:top="0dp"
                android:right="0dp"
                android:bottom="0dp" />
        </shape>
    </item>

    <item android:state_focused="true" >
        <shape>
            <solid 
                android:color="#cccccc"/>
            <corners
                android:radius="1dp" />
            <padding
                android:left="0dp"
                android:top="0dp"
                android:right="0dp"
                android:bottom="0dp" />
        </shape>
    </item>

    <item>        
        <shape>
            <solid
                 android:color="#cccccc"/>
            <corners
                android:radius="1dp" />
            <padding
                android:left="0dp"
                android:top="0dp"
                android:right="0dp"
                android:bottom="0dp" />
        </shape>
    </item>
</selector>

I define my Button in xml file:

<Button 
        android:text="Some text"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:background="@drawable/button_selector"
        android:textSize="45sp"

        android:paddingBottom="0dp"
        android:paddingTop="0dp"
        android:layout_margin="3dip"/>

But there is always padding on the top and on the bottom of the button. I've already searched SO and found some answers but nothng helped me. What could be the problem?

sinisha
  • 1,013
  • 13
  • 30

1 Answers1

3

Does setting the margin help with your situation? Try this:

     android:layout_marginTop="-3dip"
     android:layout_marginBottom="-3dip"
Xavi
  • 20,111
  • 14
  • 72
  • 63
Sam R.
  • 16,027
  • 12
  • 69
  • 122
  • This was useful. I tried negative padding values but forgot to test with negative margins. I've tried to use this with programatically made buttons but with no luck. Do you maybe have an idea how this problem could be resolved? – sinisha May 10 '13 at 14:14
  • 1
    @sinisha, if you really want to get rid of it, create your own [9-patch](http://developer.android.com/tools/help/draw9patch.html) – Sam R. May 10 '13 at 14:24
  • @sinisha, see [How to set layout_margin programmatically?](http://stackoverflow.com/a/5788570/1693859). It might help. – Sam R. May 10 '13 at 18:47
  • Thanks for your answer. I've already tried that but it didn't work – sinisha May 13 '13 at 08:04