[英]How can I change the default blue color of a selected item in Navigation drawer
I tried to use android:listSelector, but it works only when I click on the listview cell, how can I change the highlight color of a selected cell, so that the cell will be stay highlighted with that color? 我尝试使用android:listSelector,但只有当我点击listview单元格时,它才有效,如何更改所选单元格的高亮颜色,以便单元格将保持用该颜色突出显示? Many thanks.
非常感谢。
add this to your layout you use to show the elements of the listview 将此添加到您用于显示列表视图元素的布局中
android:background="?android:attr/activatedBackgroundIndicator"
Create a file res/drawable/my_background.xml with the following content : 使用以下内容创建文件res / drawable / my_background.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_activated="true" android:drawable="@color/blue" />
<item android:drawable="@android:color/transparent" />
</selector>
Replace the @color/blue with the color of your choice. 用您选择的颜色替换@ color / blue。 Then, in your theme, add the following line :
然后,在您的主题中,添加以下行:
<item name="android:activatedBackgroundIndicator">@drawable/my_background</item>
you may need to implement your own adapter in this case, and return your custom layout which background color is set to "highlight in orange". 在这种情况下,您可能需要实现自己的适配器,并返回自定义布局,其背景颜色设置为“以橙色突出显示”。 Something like this:
像这样的东西:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View your_custom_view = null;
if (convertView == null) {
your_custom_view = LayoutInflater.from(context).inflate(R.layout.your_custom_view_layout, null);
} else {
your_custom_view = convertView;
}
return your_custom_view;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.