1
私はリストビューを持っています。ユーザーがクリックしたときに背景が色を変えたいと思っています。私は休閑ファイルを持って描画可能(row_background.xml)インサイドxmlファイルからListview + Selectorがクラッシュするのはなぜですか?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/row_item"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/row_background">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/RowImg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight = "1"
android:background="#ffffff"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:minHeight="48dp"
android:maxHeight="48dp" />
<TextView android:id="@+id/RowText1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingTop="16dp"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="#000080"
android:background="#ffffff"
android:layout_weight = "2" />
</LinearLayout>
</LinearLayout>
:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:background="@color/white" />
<item android:state_focused="true" android:state_pressed="true" android:background="@color/green" />
<item android:state_pressed="true" android:background="@color/green" />
<item android:background="@color/white" />
</selector>
そして私は、値フォルダ内のカラーファイルを持っている(休閑として
各listItemのですcolor.xml):
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="green">#808080</color>
<color name="white">#ffffff</color>
</resources>
色で実行しようとすると、セレクタがクラッシュします。私は白い背景だけで実行する場合、セレクタを呼び出さずにすべてが正常に動作します。
誰かが間違っていることを教えてもらえますか?
ありがとう、 エイドリアン。 XMLでの色の
あなたは、これが解決策だと思うなぜあなたは説明できますか? – speedynomads