我在我的應用程序的代碼,點擊它時使用了AdapterView.OnItemClickListener
檢測點擊一個ListView
。問題是,當我點擊一個項目時,該項目的背景會變成白色,而不是默認的橙色。就像這樣:安卓:在列表中的項目點擊時不會變成橙色?
此外,當我不使用適配器視圖,單擊的項目變成橘紅色,沒有任何問題。如何讓點擊項目的背景變成橙色?
編輯:列表
佈局:main.xml中
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity"
android:background="#00000000">
<!-- ListView (grid_items) -->
<ListView android:id="@+id/listview"
android:layout_height="fill_parent"
android:textSize="15px"
android:layout_width="fill_parent"
android:background="#00000000">
</ListView>
</RelativeLayout>
的onCreate():
public void onCreate(Bundle savedInstanceState) {try{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
lv= (ListView)findViewById(R.id.listview);
lv.setBackgroundColor(Color.TRANSPARENT);
lv.setCacheColorHint(Color.TRANSPARENT);
//......calculations
for(int q = 0; q <v; q++){
HashMap<String, String> map = new HashMap<String, String>();
map.put("col_1", array[q]);
fillMaps.add(map);
lv.setOnItemClickListener(onListClick);
}
//......calculations
}
適配器視圖:使用
private AdapterView.OnItemClickListener onListClick=new AdapterView.OnItemClickListener(){
public void onItemClick(AdapterView<?> parent,View view, int position, long id)
{
lv.setBackgroundColor(Color.TRANSPARENT);
lv.setCacheColorHint(Color.TRANSPARENT);
//.....calculations
}
自定義主題:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomWindowTitleBackground">
<item name="android:background">#323331</item>
</style>
<style name="CustomTheme" parent="android:Theme">
<item name="android:windowTitleSize">35dip</item>
<item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
</style>
</resources>
嗨,如何發佈您正在使用的代碼? – slevon
什麼是當前使用的主題? –
@slevon新增.... –