如何将 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/