android - 自定义 AppCompatButton drawableLeft?

标签 android button android-appcompat compound-drawables

如何放置 drawableLeftAppCompatButton 的按钮文本,如下图所示?

AppCompatButton

我已尝试应用 paddingLeft,但文本从 drawable 向右移动。

<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" />

到目前为止,结果看起来像

enter image description here

布局

   <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>

以及解释清楚的要求。

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.

有什么建议吗?

最佳答案

使用

 android:drawablePadding=""

关于android - 自定义 AppCompatButton drawableLeft?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34015022/

相关文章:

ios - 单击button1时如何快速更改button2的颜色?

android - 二进制 XML 文件行 #45 : Error inflating class ImageButton onload but only on some devices

android - Gradle 构建 Android 项目 "Could not resolve all dependencies"错误

android - 更新到 Android 设计支持 22.2.1 后出现 Nullpointer 异常

android - 使用Android和OpenCV降低相机的FPS

android - 如何在 Jetpack compose OutlinedButton 中删除或减少填充

button - react native : onPress: How can I toggle the button text and function call?

Android 当插入数据不存储到数据库中时

java - 我可以制作一个包含资源文件的 Android 库吗?

swift - 按钮在程序化动态 stackView 中变为非事件状态 (Swift)