Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/192.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 安卓动画聚焦按钮(状态聚焦)_Android_Animation_Button_Imageview - Fatal编程技术网

Android 安卓动画聚焦按钮(状态聚焦)

Android 安卓动画聚焦按钮(状态聚焦),android,animation,button,imageview,Android,Animation,Button,Imageview,例如,我有几个按钮和一个ImageView。 我用键盘控制Android, 对于聚焦或按下的按钮,我使用不同的状态图像 <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/newbtfocus" /> <item android:stat

例如,我有几个按钮和一个ImageView。 我用键盘控制Android, 对于聚焦或按下的按钮,我使用不同的状态图像

 <selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="@drawable/newbtfocus" />
    <item android:state_focused="true" android:drawable="@drawable/pressednewbt" />
    <item android:state_focused="false" android:state_pressed="false" android:state_enabled="true" android:drawable="@android:color/transparent" />
    <item android:state_enabled="false" android:drawable="@color/colorAccent" />
</selector>

现在我需要更改聚焦按钮上的imageview。 例如:

  • 然后聚焦按钮1,图像视图显示Fredy Mercury
  • 然后按聚焦按钮2,图像视图显示Jackson
  • 然后聚焦按钮3,图像视图显示AC DC
等等


非常感谢您的帮助。

您可以轻松地完成以下示例中的相同操作:

btn2.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if(hasFocus){
                    // the button has focused do what you want "like below"
                    myImageView.setImageResource(R.drawable.jackson);
                }
            }
        });