我正在使用ActionBarSherlock,我正在尝试为行背景自定义activatedBackgroundIndicator属性.
如果我使用最新的android sdk,没有ActionBarSherlock,我可以自定义背景,在res/values/style.xml上创建以下样式,并在AndroidManifest.xml上将其定义为android:theme ="@ style/Theme.自定义":
<?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>
Run Code Online (Sandbox Code Playgroud)
然后,我的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>
Run Code Online (Sandbox Code Playgroud)
最后,用于定义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>
Run Code Online (Sandbox Code Playgroud)
结果显示在屏幕截图中.是一个简单的应用程序,当单击列表项时,只有ListView与ListView.CHOICE_MODE_SINGLE和getListView().setItemChecked(position,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"> …Run Code Online (Sandbox Code Playgroud) android background android-layout android-theme actionbarsherlock
我有一个简单的数组Strings,我是在水平显示ListView用ArrayAdapter.我要做的是:当用户从中选择一个项目时ListView,使该项目不可点击并更改该项目的背景颜色.也许就像一个"灰暗"的外观.我正在研究创建一个自定义Adapter并覆盖该isEnabled(int position)方法,但我不知道我会怎么做.任何建议,建议或帮助将不胜感激!