私が欲しいもの:状態リストドロアブルの<item>に複数の状態を追加すると、動作が停止します。どうして?
透明な背景を持つImageView。クリックすると背景が青色に変わり、何かがクリックされるまで青色のままになります。私はそれのための状態リストdrawableを使用しています。何が起こっている
:
次のようにコードが指定されています。 問題は、背景が青色に変わりますが、青色のままではありません。だから、android:state_pressed
は、がである瞬間を表しているにすぎないと思いました。そこで、android:state_pressed="true"
の直後にandroid:state_selected="true"
をbutton_state_list_drawable.xml
に追加しました。 それでは、画像ビューがであっても、背景が青色に変わることがなくなり、がクリックされました。
どうすれば修正できますか?このようなXMLで定義さ
ImageView
:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/fragment_imageView"
android:src="@drawable/ic_photo"
android:background="@drawable/button_state_list_drawable"
android:clickable="true" />
button_state_list_drawable.xml
である:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@drawable/button_pressed_state_drawable"
android:state_pressed="true"
android:state_selected="true" />
<item android:drawable="@drawable/button_enabled_state_drawable" />
</selector>
button_pressed_state_drawable.xml
ある:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval" >
<size android:width="50dp"
android:height="50dp" />
<padding android:left="25dp"
android:right="25dp"
android:top="25dp"
android:bottom="25dp" />
<stroke android:color="#fff"
android:width="1dp" />
<solid android:color="#1aafd0" />
</shape>
button_enabled_state_drawable.xml
である:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval" >
<size android:width="50dp"
android:height="50dp" />
<padding android:left="25dp"
android:right="25dp"
android:top="25dp"
android:bottom="25dp" />
<stroke android:color="#fff"
android:width="1dp" />
<solid android:color="@android:color/transparent" />
</shape>
残りの['button states'](http://developer.android.com/guide/topics/resources/color-list-resource.html)(' focused'、 'selected'など)を追加しようとしましたか?多分あなたは状態を渡し、色はデフォルトの状態に戻ります。 – yennsarah