導航:首頁 > 操作系統 > androidlistview點擊背景

androidlistview點擊背景

發布時間:2023-03-23 07:42:08

android listview點擊背景改變,點擊其他事背景變回原來的樣子,被點擊的改變

<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android ">手隱握
<item android:state_window_focused="false"
android:drawable="@drawable/沒有焦點時的圖片背景" />
<item android:state_focused="true" android:state_pressed="true"
android:drawable=
"@drawable/非觸摸模式下獲得焦點並單擊時的背景圖片" />
<item android:state_focused="false" android:state_pressed="true"
android:drawable="@drawable/觸摸模式下單擊時的背景圖片" />
<item android:state_selected="true"
android:drawable="@drawable/選中時的圖片背景" />畢慶
<item android:state_focused="true"
android:drawable="@drawable/獲得焦點時的圖片背景" />
</selector>

在ListView布局攜敗中設置android:listSelector。。。。

Ⅱ 實現android中listView的item點擊變背景色

我的錯沒看清楚褲岩問滲銷題。
按題主代碼自測在4.4.2上面沒有出現該問題。
---------------------原答案分隔線------------------------
你這樣寫的代碼胡喊御不是最優的,一種比較好的寫法是自定義Adapter,在getview方法裡面自定義一個list的item的xml文件,在xml裡面用自定義selector。而listview在xml裡面的屬性中listSelector要設置為空就是android:listSelector="@null"

Ⅲ android listView 怎麼指定項的背景設置

android listview指定項設定背景步驟如下:

  1. 監聽列表項監聽事件,取得被點擊的view,設置為:view.setSelector("true");

2.在適配器塌鎮中,用if-else語句,判斷選擇的列表項設置背景,沒有選中的則默認背景,代碼如下:


java">try{
if(selectItem==position){
messagetitle.setTextColor(android.graphics.Color.BLACK);
messagetime.setTextColor(android.graphics.Color.BLACK);
viewHolder.messagetitle.setText(maps.get(position)
.get("messagetitle").toString());
viewHolder.messagetime.setText(maps.get(position)
.get("messagetime").toString());
convertView.findViewById(R.id.expandable1)
.setBackgroundColor(android.graphics.Color.WHITE);
convertView.findViewById(R.id.expandable1)
.setBackgroundResource(R.drawable.menu_shapeclick);
}else{
messagetitle.setTextColor(android.graphics.Color.WHITE);
messagetime.setTextColor(android.graphics.Color.WHITE);
viewHolder.messagetitle.setText(maps.get(position)
.get("messagetitle").toString());
viewHolder.messagetime.setText(maps.get(position)
孫鬧.get("messagetime").toString());
convertView.findViewById(R.id.expandable1)
.setBackgroundResource(
團凱粗R.drawable.menu_shapeunonclick);
}
}catch(Exceptionex){
ex.printStackTrace();
}
returnconvertView;
閱讀全文

與androidlistview點擊背景相關的資料

熱點內容
關於改善國家網路安全的行政命令 瀏覽:825
安卓如何下載網易荒野pc服 瀏覽:646
javainetaddress 瀏覽:95
蘋果4s固件下載完了怎麼解壓 瀏覽:994
命令zpa 瀏覽:277
python編譯器小程序 瀏覽:936
在app上看視頻怎麼光線調暗 瀏覽:532
可以中文解壓的解壓軟體 瀏覽:584
安卓卸載組件應用怎麼安裝 瀏覽:904
使用面向對象編程的方式 瀏覽:331
程序員項目經理的年終總結範文 瀏覽:920
內衣的加密設計用來幹嘛的 瀏覽:424
淮安數據加密 瀏覽:287
魔高一丈指標源碼 瀏覽:974
松下php研究所 瀏覽:162
c回調java 瀏覽:391
夢幻端游長安地圖互通源碼 瀏覽:738
電腦本地文件如何上傳伺服器 瀏覽:304
單片機晶振不好怎麼辦 瀏覽:572
安卓時時監控源碼 瀏覽:937