0

in my application I'm using instead of Buttons, ImageViews which have a selector as background. They are working fine though the focus is lost really quickly and as a result the effect isn't visible to the user 100%. Is there a way that I can delay the focus which the views receive for like a second? another way that I've tried was to change the ImageView's background when it was touched and change it back on the onPause()

Background Selector

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
    android:drawable="@drawable/actionbar_background" />
<item  android:state_focused="false" 
    android:drawable="@drawable/normal" />
</selector>

normal.xml

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
<solid android:color="#FFFFFF"/>    
</shape>
Libathos
  • 3,340
  • 5
  • 36
  • 61

1 Answers1

0

Ok this is what I did to overcome it I changed the background selector as

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" 
    android:drawable="@drawable/actionbar_background" />
<item android:state_selected="true" 
    android:drawable="@drawable/actionbar_background" />
<item  android:state_pressed="false" 
    android:drawable="@drawable/normal" />
</selector>

and on the function bound by the image view

v.setSelected(true);
selectedView = v;

and on onStop()

selectedView.setSelected(false);

Hope this will help anyone who stumbles upon this post

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Libathos
  • 3,340
  • 5
  • 36
  • 61