我之前有过这个工作,但由于某种原因我无法再改变背景颜色了。我正在使用带有multiChoiceModeListener的cab和标准列表视图。
mainActivity布局中的Listview:
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/listView"
android:divider="@null"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
Listview项目布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:descendantFocusability="blocksDescendants"
android:background="?android:attr/activatedBackgroundIndicator"
android:paddingRight="8dp"
android:paddingLeft="8dp"
android:layout_height="80dp">
<TextView
android:id="@+id/lvNum"
android:layout_width="match_parent"
android:layout_height="50dp"
android:singleLine="true"
android:text="100"
android:textSize="42dp"
style="@android:style/TextAppearance.DeviceDefault.Large"
android:layout_alignParentTop="true" />
<TextView
android:id="@+id/lvName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Counter Name"
android:singleLine="true"
android:ellipsize="end"
android:paddingRight="140dp"
android:textSize="22dp"
android:layout_below="@+id/lvNum" />
<Button
android:layout_width="70dp"
android:layout_height="80dp"
android:id="@+id/subtractButt"
android:text="-"
android:textAlignment="center"
android:textSize="45dp"
android:layout_toStartOf="@+id/addButt"
android:layout_toLeftOf="@+id/addButt" />
<Button
android:layout_width="70dp"
android:layout_height="80dp"
android:id="@+id/addButt"
android:text="+"
android:textSize="45dp"
android:layout_alignParentRight="true"
android:textAlignment="center" />
样式(我最近添加了第二个主题,但我已经删除了它使用的任何地方)
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primaryDark</item>
<item name="colorAccent">@color/accent</item>
<item name="android:navigationBarColor" tools:targetApi="21">@color/primary</item>
<item name="android:activatedBackgroundIndicator">@drawable/list_activated_background</item>
</style>
<style name="AppThemeDark" parent="Theme.AppCompat">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/primaryDark</item>
<item name="colorPrimaryDark">@color/primaryDark</item>
<item name="colorAccent">@color/accentDark</item>
<item name="android:navigationBarColor" tools:targetApi="21">@color/primaryDark</item>
<item name="android:activatedBackgroundIndicator">@drawable/list_activated_background</item>
</style>
list_activated_background(更改颜色无效)
<?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/selected" />
<item android:drawable="@android:color/transparent"/>
</selector>
感谢您的帮助,我完全被困在这里。
答案 0 :(得分:0)
我最后放弃了我添加的自定义适配器中的activatedBackgroundIndicator:
vi.setBackgroundResource(R.drawable.list_activated_background);