Customize AppCompatButton drawableLeft?
Asked Answered
T

3

7

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?

Thadthaddaus answered 1/12, 2015 at 7:40 Comment(0)
N
5

use

 android:drawablePadding=""
Neurath answered 1/12, 2015 at 7:44 Comment(2)
drawablePadding only makes padding b/w the button text and drawable.Thadthaddaus
Completely your misunderstand my query plz see the updated one.Thadthaddaus
V
0

probably you can't, if you want like this then you have to make it using complex layout like this see

Venturous answered 1/12, 2015 at 8:2 Comment(0)
W
0

Add padding to the right too; that will push the text and the drawable closer together. Keep adjusting these values to get desired result.

See below:

android:drawableStart="@drawable/ic_water_now"
    android:paddingLeft="10dp"
    android:paddingRight="21dp"

Sample result:

Here is the results

Waisted answered 9/8, 2023 at 20:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.