Android highlight an imagebutton when clicked -


I am using an ImageButton . But when I click, I get highlighted. I have googled and suggested to use multiple selectors where another image is displayed. Is there a way around it? Using only one image and highlighting it or giving a glowing effect so that the user knows that the button has been clicked.

This is not really difficult to do. You do not need to create 2 different .png files or anything like that. For example, if you want a button that has a gradient, then change it when the button is pressed:

Step 1: Create the default button gradient (double / default_button.xml):

  & lt; Size xmlns: Android = "http://schemas.android.com/apk/res/android" Android: Shape = "Rectangle" & gt; & Lt; Corners Android: Radius = "3dp" /> & Lt; Shield Android: endColor = "# 8ba0bb" Android: startColor = "# 43708f" Android: Angle = "90" /> & Lt; Stroke Android: width = "1dp" Android: color = "# 33364252" /> & Lt; / Size & gt;   

Step 2: Create the default button pressed shield (Drawable / Default_button_pressed.xml):

   & Lt; Shield Android: endColor = "# 43708f" Android: startColor = "# 8ba0bb" Android: Angle = "90" /> & Lt; Stroke Android: width = "1dp" Android: color = "# 33364252" /> & Lt; / Size & gt;   

Step 3: Create selector (Dribbble / Default_button_sector.xml):

   & Lt; Item Android: Dragon = "@ Drable / Default_button" /> & Lt; / Selector & gt;   

Step 4 (optional) : Create a style for the button (Value / Style .xml):

  & lt; Resources & gt; & Lt; Style name = "DefaultButton" & gt; & Lt; Item name = "Android: layout_width" & gt; Rap_news & lt; / Item & gt; & Lt; Item name = "Android: Layout_hete" & gt; Rap_news & lt; / Item & gt; & Lt; Item name = "Android: Background" & gt; @drawable / default_button_silctor & lt; / Item & gt; & Lt; / Style & gt; & Lt; / Resources & gt;   

Step 5: Use the Button (Layout / Main .xml):

  & lt; LinearLayout xmlns: android = "http://schemas.android .com / apk / res / android" android: layout_width = "fill_parent" android: layout_height = "fill_parent" & gt; & Lt; Button style = "@ style / default button" /> & Lt; / RelativeLayout & gt;   

As you can see, it is not particularly difficult to do this.

Comments