【发布时间】:2019-02-08 13:44:17
【问题描述】:
我有一个列表视图设置为使用 singleChoice。我要做的就是将默认背景颜色更改为白色,将文本颜色更改为黑色。我无法弄清楚如何做到这一点。这是我的 xml 布局:
<ListView
android:id="@+id/lvSpeeds"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/llToolbar"
android:layout_below="@id/rgSpeedUnits"
android:textColor="@android:color/black"
android:choiceMode="singleChoice"
android:background="#ffffff"
android:cacheColorHint="#00ffffff"
android:clickable="true"
android:divider="#ff000000"
android:dividerHeight="1dp"
android:focusable="true"
android:scrollingCache="true" />
编辑:我应该指出我只想使用 xml 布局文件而不是代码来更改它。我已经知道如何在代码中做到这一点。使用 android.R.layout.simple_list_item_single_choice 以外的自定义布局会强制您实现适配器、绑定、编写更多代码等等。从查看更多帖子来看,似乎无法仅使用 xml 更改文本颜色。事实上,由于底层布局 android.R.layout.simple_list_item_single_choice 无法访问,因此似乎无法更改一行中的任何内容。
【问题讨论】:
-
为 textView 创建不同的布局,设置您想要的文本颜色,并在您使用的适配器中使用此布局。看看这个link它会对你有所帮助。