focus - Android layout - ImageView focused, but doesn't show anything on screen (no highlight) -


if set imageview both clickable , focusable, works, have no way tell image focused. what's best way draw orange border around view user knows it's in focus?

i tried dropping in linearlayout , setting focusable , clickable instead, didn't have luck. when put margin on it, there's nothing indicate selected.

you can use drawable selector background.

for example, have gallery_image_bg.xml in res/drawable:

<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"           android:constantsize="true">   <item android:state_selected="true">     <shape android:shape="rectangle">       <solid android:color="#e6e4e0"/>       <stroke android:width="3dp" android:color="#f9c11e"/>       <padding android:left="3dp"                android:top="3dp"                android:right="3dp"                android:bottom="3dp" />     </shape>   </item>   <item android:state_pressed="true">     <shape android:shape="rectangle">       <solid android:color="#e6e4e0"/>       <stroke android:width="3dp" android:color="#f9c11e"/>       <padding android:left="3dp"                android:top="3dp"                android:right="3dp"                android:bottom="3dp" />     </shape>   </item>   <item>     <shape android:shape="rectangle">       <solid android:color="#e6e4e0"/>       <stroke android:width="3dp" android:color="#fff"/>       <padding android:left="3dp"                android:top="3dp"                android:right="3dp"                android:bottom="3dp" />     </shape>   </item> </selector> 

this creates 3 different-colored 3dp lines around image. visible because padding forces image render in smaller area.

used in code so:

image.setbackgroundresource(r.drawable.gallery_image_bg) 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -