简体   繁体   中英

Android Animation on focused button (state_focused)

For example i have few buttons, and one ImageView. I using keyboard to control the Android, For focused or pressed button i use different state image.

 <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>

Now i need to change the imageview on focused button. For example:

  • Then focused button 1 the imageview show Fredy Mercury.
  • Then focused button 2 the imageview show Jackson.
  • Then focused button 3 the imageview show AC DC

and other.

Thank's a lot for any help.

Easily you can do same of this example below:

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);
                }
            }
        });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM