我在用着动作栏夏洛克我正在尝试定制激活背景指示器行背景的属性。
如果我使用最新的android sdk,没有动作栏夏洛克,我可以自定义背景,创建以下样式资源/值/style.xml并将其定义为AndroidManifest.xml as android:主题=“@style/Theme.Custom”:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Custom" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:activatedBackgroundIndicator">@drawable/activated_background</item>
</style>
</resources>
然后,我的res/drawable/activated_background.xml包含下一个代码:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_activated="true" android:drawable="@color/row_activated" />
<item android:drawable="@android:color/transparent" />
</selector>
最后,用于定义 ListView 中每一行的代码是:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="?android:attr/activatedBackgroundIndicator">
<TextView
android:id="@+id/test_row"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/sample_string"
android:textAppearance="?android:attr/textAppearanceMedium"
android:padding="15dp"/>
</LinearLayout>
结果显示在屏幕截图中。是一个简单的应用程序,只有一个 ListViewListView.CHOICE_MODE_SINGLE and getListView().setItemChecked(位置,true)单击列表项时。
标准选定行的蓝色现在变为黄色,并且效果完美。
当我想使用 ActionBarSherlock 应用相同的自定义时,就会出现问题。
现在是样式文件,背景显示为蓝色而不是自定义黄色。
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Custom" parent="Theme.Sherlock.Light.DarkActionBar">
<item name="activatedBackgroundIndicator">@drawable/activated_background</item>
<item name="android:activatedBackgroundIndicator">@drawable/activated_background</item>
</style>
<style name="activatedBackgroundIndicator">
<item name="android:background">?android:attr/activatedBackgroundIndicator</item>
</style>
</resources>
我不知道是否动作栏夏洛克支持android:activatedBackgroundIndicator功能或者如果我忘记实现需要能够更改默认颜色的东西。
有任何想法吗?