How can I make make a border for a clicked imagebutton in Android? -


I am using Imagebuttons to show some icons in my Android project.

  & lt; Android: layout_height = "wrap_content" android: layout_alignParentLeft = "true" Android: layout_alignParentTop = "true" Android: padding = "20dp" Android: contentDescription = "@ String / button_on" Android: background = "@ Android: color / transparent" Android: src = "@drawable / button_on" />  

I think, when the button is in a pressed state, there will be a white border with rounded corners. What can I do to do this? Can this just be used on code or will I need an extra background image?

This is a method if you do not want to create separate images with the border

Make Drawable XML with your border style (e.g., border.xml)

   & Lt; Padding android: left = "1dp" android: top = "1dp" Android: right = "1dp" Android: Below = "1dp" /> & Lt; Corners Android: bottomRightRadius = "8dip" Android: bottomLeftRadius = "8dip" Android: topRightRadius = "8dip" Android: topLeftRadius = "8dip" /> & Lt; / Size & gt;  

Make selector drawable (eg some_selector_name.xml). When pressed basically, it will show your border painting. Otherwise, it would be transparent.

  & lt; Selector xmlns: android = "http://schemas.android.com/apk/res/android" & gt; & Lt; Item Android: state_pressed = "true" android: drawable = "@ drawable / border" /> & Lt; Item android: drawable = "@ android: color / transparent" /> & Lt; / Selector & gt;  

Set your background of your image button to drawable your selector

; ImageButton Android :. Android: layout_width = "wrap_content" android: layout_height = "wrap_content" Android: layout_alignParentLeft = "true" Android: layout_alignParentTop = "true" Android: padding = "20dp" Android: Content Circles = "@ String / button_one "Android: background =" @ drawable / some_seller_name.exml "Android: src =" @drawable / button_on "/>  

Now when you press the button, it should display the white border. This is just an example but you should get this idea.


Comments

Popular posts from this blog

eclipse plugin - Run java code error: Workspace is closed -

ios - How do I use CFArrayRef in Swift? -

file rename - Git : Not under version control fatal error -