ListView 中每個 Item 包含 TextView 和 Button。使用遙控器/方向鍵導航時:
ListView 默認 itemsCanFocus = false,但 Item 佈局中存在可聚焦控件 (Button、EditText 等) 時,Android 會同時維護兩套焦點體系:
listView.setItemsCanFocus(true);
設置後,ListView 將焦點管理完全委託給 View 系統,Item 本身不再接收焦點,子控件 (Button) 成為唯一焦點接收者,雙焦點問題瞬間消失。
<!-- Item 佈局根佈局 -->
<LinearLayout
android:id="@+id/item_root"
android:focusable="true"
android:focusableInTouchMode="true"
android:background="@drawable/item_selector"> <!-- selector 控制選中態 -->
<Button ... />
</LinearLayout>
配合 listView.setItemsCanFocus(true),根佈局攔截焦點,按鈕僅響應點擊,可實現「整行高亮 + 按鈕可點」的交互。
android:descendantFocusability,易產生更詭異行為recyclerView.setItemsCanFocus(true) (默認即為 true)ChoiceMode (單選/多選),需在 Adapter 中根據 isSelected() 手動刷新 Item 背景理解「Item 焦點 vs 子控件焦點」的雙軌制,是 Android 列表交互開發的必經之路。