【发布时间】:2017-02-10 16:20:33
【问题描述】:
我想突出显示 list view 中的特定行项目以显示为选定项目。
我有一个国家列表,我想突出显示一个国家,以便通过按钮选择它。
我用过这个:
<ListView
android:id="@+id/list_country"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/doneBtn"
android:choiceMode="singleChoice"
android:listSelector="@drawable/list_selector"
android:layout_below="@+id/image_logo">
</ListView>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@drawable/list_selector">
<TextView
android:id="@+id/country_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_gravity="center"
android:text="CountryName"
android:textSize="24sp"/>
</LinearLayout>
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initViews();
mCountryAdapter = new CountryAdapter(this, R.layout.single_country, countryList);
mListViewCountry.setAdapter(mCountryAdapter);
mListViewCountry.setSelector(R.drawable.list_selector);
clickListeners();
}
这是我的选择器:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@color/color_selector"/>
<item android:state_selected="true" android:drawable="@color/color_selector"/>
</selector>
当我点击或按下项目时它只是改变颜色,如果我移除触摸,它会改变为默认颜色!任何人都可以帮我解决我所缺少的
【问题讨论】:
-
这可以通过enter link description here来完成