Ion*_*ers 5 android attributes android-selector
我正在尝试创建一个使用所选主题定义的属性的选择器。
属性文件
<declare-styleable name="ThemeColors">
<attr name="buttonTextColor" format="color" />
</declare-styleable>
Run Code Online (Sandbox Code Playgroud)
选择器.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" android:color="@android:color/black" />
<item android:color="?attr/buttonTextColor"/>
</selector>
Run Code Online (Sandbox Code Playgroud)
主题:
<style name="Theme.Test" parent="@style/Theme.AppCompat">
<item name="buttonTextColor">@android:color/white</item>
</style>
Run Code Online (Sandbox Code Playgroud)
部分布局文件:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/test"
android:textColor="@drawable/selector" />
Run Code Online (Sandbox Code Playgroud)
显现
<application
...
android:theme="@style/Theme.Test" >
Run Code Online (Sandbox Code Playgroud)
布局文件由该setContentView方法膨胀。
现在的问题是 textcolorRED处于未按下状态(按下时为黑色)。似乎找不到buttonTextColor并使用默认值RED(?)
已经尝试将主题设置为应用程序上下文,但没有运气..
提前致谢。
| 归档时间: |
|
| 查看次数: |
220 次 |
| 最近记录: |