不能在 android 的样式标签中使用背景元素

问题描述 投票:0回答:0

我正在尝试使用样式将自定义样式应用于 android 中的文本视图。但不幸的是我在运行时遇到了这个异常。

android.view.InflateException: Binary XML file line #59 in com.myapp.android:layout/fragment_draw: Binary XML file line #59 in com.mirana.android:layout/fragment_draw: Error inflating class TextView
Caused by: android.view.InflateException: Binary XML file line #59 in com.mirana.android:layout/fragment_draw: Error inflating class TextView
Caused by: android.content.res.Resources$NotFoundException: Drawable com.mirana.android:drawable/drawable_button_background_filled with resource ID #0x7f080482
Caused by: java.lang.UnsupportedOperationException: Can't convert value at index 0 to dimension: type=0x4

draw_layout_frag.xml

 <TextView
  android:id="@+id/btn_clear"
  style="@style/buttonDrawSectionTypeFilledStyle"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:text="Clear" />

themes.xml

 <item name="drawableButtonBgDrawSectionFilled">@drawable/drawable_button_background_filled</item> 

attrs.xml

 <attr name="drawableButtonBgDrawSectionFilled" format="reference" />

style.xml

 <style name="buttonDrawSectionTypeFilledStyle">
    <item name="android:background">?attr/drawableButtonBgDrawSectionFilled</item>
    <item name="android:layout_height">@dimen/_40sdp</item>
    <item name="android:layout_width">wrap_content</item>
    <item name="android:textColor">?attr/colorBaseRed</item>
</style>

drawable_button_background_filled.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
  <corners android:radius="12dp" />
  <stroke
    android:width="4dp"
    android:color="?attr/colorBaseRed" />
</shape>

我的问题是,是否无法在样式中使用背景元素,还是我在代码中做错了什么?

android xml android-layout android-drawable android-styles
© www.soinside.com 2019 - 2024. All rights reserved.