默认情况下,ListView
在按下时将背景颜色更改为橙色,并且 TextView
的 TextColor
更改为白色/黑色。通过在 ListView
项目上应用选择器,我们可以为按下状态设置背景颜色,但我们也可以为该项目内的 TextView
定义 TextColor
/layout 在同一个选择器中?如果是,那怎么办?
Amy88 的回答解决了这个问题,但没有专门解决更改 ViewGroup 的子属性的问题。
假设您有一个可点击的 LinearLayout
和一个 TextView
,当按下它时应该会改变颜色。关键是在 subview 上使用 android:duplicateParentState="true"
:
<LinearLayout
android:duplicateParentState="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
androidrientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:duplicateParentState="true"
android:text="@string/hello_world"
android:textColor="@drawable/text_selector" />
</LinearLayout>
您可以按照 Amy88 的答案指定选择器。
关于android - 使用布局的选择器更改其子项的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8211203/
欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) | Powered by Discuz! X3.4 |