android - 带 xml 图标的 DrawableLeft

标签 android android-layout

如何将 drawableLeft 与 xml 图标一起使用?我有以下按钮:

<Button
   android:id="@+id/vitimas"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:layout_marginBottom="10dp"
   android:layout_marginLeft="20dp"
   android:layout_marginRight="20dp"
   android:drawableLeft="@drawable/ic_person_black_24dp"
   android:drawableStart="@drawable/ic_person_black_24dp"
   android:background="@drawable/botao_verde"
   android:text="Vítimas"/>

在 16 等旧 API 中,应用程序因 drawableLeft 而停止工作,我尝试使用 ImageButton 但如果我使用 app,也会发生同样的情况: srcCompat 它可以工作,但是图标不在左边,我需要它在左边,文本在中间

图标来自 Vector Asset 包。

最佳答案

AppCompatTextView supports app:drawableLeftCompat, app:drawableTopCompat, app:drawableRightCompat, app:drawableBottomCompat, app:drawableStartCompat app:drawableEndCompat 复合绘图,支持向后移植的绘图类型,例如 VectorDrawableCompat

将其包含在你的 gradle 文件中

implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
implementation 'androidx.appcompat:appcompat-resources:1.1.0-rc01'

在你的 TextView 中你可以使用

app:drawableLeftCompat
app:drawableStartCompat

关于android - 带 xml 图标的 DrawableLeft,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49985793/

相关文章:

android RTP收发程序

android - 水平 ScrollView 的问题自动滚动到 Edittext 焦点

android - Flutter - TextFormField 上的键盘

android - 来自 XML 字符串的 HashMap - Android

android - 在 Android 上使用 facebook SDK 会出现 "User logged in as different Facebook user."错误

android - 如何让ListView中的元素垂直居中?

android - 无法在android中相对布局的顶部和下方获得黑色 strip

android - ScrollView 内的 RelativeLayout 不滚动。我做错了什么?

安卓扭曲的用户界面

android定义的属性和自定义属性并排在自定义 View 上