问题描述
<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 (将#修改为@)