Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set distance betwen textview and drawable in a button?

okey guys, i've a button like the pict below enter image description here

i want to change the distance between the text with the drawable . how to trick this one ?

this is my xml code for a button

<Button
   android:id="@+id/ButtonCancel"
   style="@style/CAGButton"
   android:drawableLeft="@drawable/selector_ic_cancel"
   android:text="@string/layer_button_cancel" />

and this is the CAGButton in style.xml

<style name="CAGButton" parent="@android:style/Widget.Button">
    <item name="android:drawablePadding">3dip</item>
    <item name="android:textColor">@color/cag_brown</item>
    <item name="android:layout_width">0dp</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:layout_weight">1</item>
    <item name="android:background">@drawable/selector_button"</item>
</style>

okey, thanks in adv. :)

like image 640
Khairil Ushan Avatar asked Jul 23 '13 06:07

Khairil Ushan


2 Answers

Btw i solved my problem with made some changes in my button style. so it become like this :

    <style name="CAGButton" parent="@android:style/Widget.Button">
        <item name="android:gravity">center</item>
        <item name="android:paddingLeft">20dp</item>
        <item name="android:paddingRight">20dp</item>
        <item name="android:textColor">@color/cag_brown</item>
        <item name="android:layout_width">0dp</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:layout_weight">1</item>
        <item name="android:background">@drawable/selector_button</item>
    </style>

I think we just need to set the padding left &/ right to the best point that fit our design.

like image 167
Khairil Ushan Avatar answered Oct 18 '22 18:10

Khairil Ushan


Here is the solution.

                    <Button
                    android:id="@+id/xyz"
                    android:layout_width="wrap_content"
                    android:layout_height="30dp"
                    android:layout_weight="1"
                    android:background="@drawable/button_shape"
                    android:drawableLeft="@drawable/location"
                    android:drawablePadding="2dip"
                    android:gravity="center"
                    android:paddingLeft="20dip"
                    android:paddingRight="16dip"
                    android:singleLine="true"
                    android:text="XYZ"
                    android:textColor="#FFF" />
like image 20
Prem Tomar Avatar answered Oct 18 '22 19:10

Prem Tomar