【发布时间】:2020-03-15 08:34:18
【问题描述】:
我正在尝试创建一个具有两个背景的按钮,即我的自定义背景
android:background="@drawable/background_profile_edit_button" + ?attr/selectableItemBackground```
完整按钮:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/fragprofile_constraint"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:background="@drawable/background_profile_edit_button"
android:paddingStart="32dp"
android:paddingTop="6dp"
android:paddingEnd="32dp"
android:paddingBottom="6dp"
android:text="Edit Profile"
android:textColor="@color/colorBlackFont"
android:textSize="12sp"
android:textStyle="bold"/>
这可以通过android:foreground="?attr/selectableItemBackground" 轻松解决,但这需要 api 23 而我的最小值是 19。
我还尝试了另一种在可绘制对象中使用图层列表的方法:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape
android:shape="rectangle">
<solid android:color="@color/colorWhite" />
<stroke
android:width="1dp"
android:color="@color/dividerColor" />
<corners android:radius="3dp"/>
</shape>
</item>
<item
android:drawable="?attr/selectableItemBackground">
</item>
</layer-list>
这个层列表在我的更高 API 设备上完美运行。但是它导致我的 API 19 设备崩溃...
android.view.InflateException: Binary XML file line #201: Error inflating class TextView
这个人也有同样的问题,也没有答案:
LayerList error API 19: tag requires a 'drawable' attribute or child tag defining a drawable
TLDR:_____________________________________________
在 API 19 设备上执行此操作
【问题讨论】:
标签: android layer-list