我必須關注所有可點擊的項目,以便用戶知道焦點在哪裏。但問題是,我可以專注於列表行,如果我添加
查看越來越掛斷由於排文件中的多個視圖,以獲得點擊你要多一個屬性添加到您的行XML的主要佈局。
android:descendantFocusability="blocksDescendants
但是,當我寫上面的屬性,則我不能夠集中的ImageButton這是在我行的文件。
我只是試過一種方法獲得ImageButton
以及listview
foucus。
要獲得ImageButton的重點:
- 創建一個選擇文件。
- 應用於Imagebutton。
- 向ImageButton添加了
android:focusableInTouchMode="true"
。
要獲取列表視圖的焦點:
- 行XML中添加
android:descendantFocusability="blocksDescendants
主佈局。
現在,當你點擊你的ImageButton時,它將關注你想要的顏色,即使它也會專注於listview點擊。
Selecotor.xml
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android"
>
<item
android:state_pressed="true"
android:drawable="@android:color/transparent"
/> <!-- pressed -->
<item
android:state_focused="true"
android:drawable="@android:color/darker_gray"
/> <!-- focused -->
<item
android:drawable="@android:drawable/btn_star"
/> <!-- default -->
</selector>
在S3模擬器測試,效果很好。
我做了所有上述的事情,但它不適用於nexus 7模擬器以及電視。我認爲它是因爲沒有電視觸摸屏,所以android:focusableInTouchMode =「true」不起作用 – 2013-04-01 13:56:24
它在nexus 7模擬器中工作也很好。 – RobinHood 2013-04-02 09:15:03
重點是要列出行和按鈕...? – 2013-04-02 09:18:43