ListViewに入れるViewのbackgroundに色を直接指定しちゃだめ
フォーカスがどこにあるのかわからなくなるから、キーボード操作できなくなる。
「タッチ操作には何の問題もない!!」と思うかもしれないけど、タッチしたときのフィードバック(押されたときに色が変わるやつ)が無くなるから、タッチ操作もしにくくなる。
よく知らないけど Google TV でアプリが動くようになったらカーソルキーできないと困るんじゃないかな。たぶん...。
直接指定してしまう
list_row.xml
<?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:background="#fff" android:layout_width="fill_parent" android:layout_height="wrap_content"/>
focusedやpressedを考慮する
まず、styles.xml で背景色を設定する。
values/styles.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <color name="list_row_background_normal">#0ff</color> </resources>
次に、selector を使って、pressed, focused, selectedのときは透明で、それ以外のときだけ塗られる @drawable/list_row_background を作る。
res/drawable/list_row_background.xml
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@android:color/transparent" android:state_pressed="true" /> <item android:drawable="@android:color/transparent" android:state_focused="true" /> <item android:drawable="@android:color/transparent" android:state_selected="true" /> <item android:drawable="@android:color/transparent" android:state_window_focused="false" /> <item android:drawable="@color/list_row_background_normal" /> </selector>
作った @drawable/list_row_background を @layout/list_row の background に設定する。
list_row.xml
<?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:background="@drawable/list_row_background" android:layout_width="fill_parent" android:layout_height="wrap_content"/>
これでとりあえず、押されたときや選択されたときにオレンジ色のやつが表示されるようになるので、操作に問題はなくなると思う。