Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customize AppCompatButton drawableLeft?

How can I place drawableLeft and button text of AppCompatButton like in the image below?

AppCompatButton

I have tried to apply paddingLeft, but the text is moving away from the drawable to the right.

<android.support.v7.widget.AppCompatButton
                android:id="@+id/filterBy"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:drawableLeft="@drawable/ic_btn_filter"
                android:paddingLeft="20dp"
                android:text="@string/filter_by"
                android:textAllCaps="false" />

And so far the result is looking like

enter image description here

Layout

   <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/profileHeader"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:layout_marginTop="10dp">

            <android.support.v7.widget.AppCompatButton
                android:id="@+id/findFriends"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:drawableLeft="@drawable/ic_btn_search"
                android:text="@string/find_friends"
                android:textAllCaps="false" />

            <android.support.v7.widget.AppCompatButton
                android:id="@+id/filterBy"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:drawableLeft="@drawable/ic_btn_filter"
                android:text="@string/filter_by"
                android:textAllCaps="false" />
      </LinearLayout>

And the interpreted requirement for making things clear.

Using layout_weight property am adjusting the width of both buttons and what i have to do is, the text should be in center of the button and the drawable should be aligned near left of the text.

Any suggestion please?

like image 732
Stella Avatar asked Dec 01 '15 07:12

Stella


People also ask

How do I change the icon size on a Drawableleft button?

You can control the size of the icon by changing scaleX and scaleY. This is useful not only in case of drawables but any place where an icon is used and where it is not easy to find styling solutions to reduce icon size like say an AlertDialogue. Show activity on this post. Best Way you can use ImageView.

What is appcompat button?

AppCompatButton widget enhanced with emoji capability by using EmojiTextViewHelper . A Button which supports compatible features on older versions of the platform, including: Allows dynamic tint of its background via the background tint methods in ViewCompat . Allows setting of the background tint using R. attr.

How can set image in center of button in Android?

Create a RelativeLayout "wrap_content" with the button image as the background or the button itself as the first element of the layout. Get a LinearLayout and set it to "layout_centerInParent" and "wrap_content". Then set your Drawable as an Imageview.


1 Answers

use

 android:drawablePadding=""
like image 64
Vaisakh N Avatar answered Oct 05 '22 18:10

Vaisakh N