带有Alpha的Android MDC属性

问题描述

我使用下一个代码制作了一个简单的除法器

<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/colorOnSurface"
... />

但是我想将背景颜色设置为colorOnSurface 并带有alpha

我知道我可以简单地在颜色的开头添加两个字母的十六进制:

android:background="#20352921"

但是由于我使用的是深色主题,并且希望保留一个真实的来源,所以我想基于?attr/colorOnSurface

创建一种颜色

基于this page,我在color库中创建了on_surface_10.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:alpha="0.1" android:color="?attr/colorOnSurface" />
</selector>

并尝试这样替换背景颜色:

<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/on_surface_10"
... />

但是应用程序崩溃了

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.android.glist,PID: 22616
    android.view.InflateException: Binary XML file line #131: Binary XML file line #131: Error inflating class <unkNown>
    Caused by: android.view.InflateException: Binary XML file line #131: Error inflating class <unkNown>
    Caused by: java.lang.reflect.InvocationTargetException
...
     Caused by: android.content.res.Resources$NotFoundException: Drawable com.android.glist:color/on_surface_10 with resource ID #0x7f0600c7
     Caused by: android.content.res.Resources$NotFoundException: File res/color/on_surface_10.xml from drawable resource ID #0x7f0600c7
        at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:847)

我在网上看了一下,但不明白我在做什么错

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...