Android: Is there a better way to create this View that has two States? -


I am trying to create a scene with two states - there is a 'ready' state and 'pressed' state .

The way in which it is currently implemented is disabled. Both states of the button are coded into layouts:

   & Lt; TextView android: id = "@ + id / strut_1_value" style = "@ style / StrutValue" android: text = "@ string / placeholder_text_short" / & gt; & Lt; / RelativeLayout & gt; & Lt ;! - 'Pressed' state button - & gt; & Lt; RelativeLayout android: id = "@ + the id / strut_button_1_complete run" style = "@ style / StrutButtonComplete" Android: visibility = "" & gt; & Lt; TextView Android: id = "@ + id / strut_1_badge" style = "@ style / Strut1Badge" Android: text = "1" /> & Lt; TextView android: id = "@ + id / strut_1_value" style = "@ style / StrutValueComplete" android: text = "@ string / placeholder_text_short" / & gt; & Lt; TextView style = "@ style / checkmark" Android: text = "\ u2714" Android: layout_gravity = "center_ current | true" /> & Lt; / RelativeLayout & gt;  

I button to extend visibility set some operators to toggle when "pressed" state button ready, it turns on GONE your visibility, and pressed ' 'State changes the button to show visibility.

I considered using a selector for the button, but the selector was not able to give me the button layout I needed. Is there a better way for me to do this now?

Try using XML drawables which sets states:

  & lt;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; Selector xmlns: Android = "http://schemas.android.com/apk/res/android" & gt; & Lt; Item Android: Dragon = "@ Drauble / Color_Dialody_scheduled" Android: state_focused = "true" /> & Lt; Item Android: Dragon = "@ Drawable / Color_Drio_ Selected" Android: state_pressed = "true" /> & Lt; Item Android: Doubles = "@drawable / color_dido_choose" Android: state_selected = "true" /> & Lt; Item Android: Dragon = "@ Drauble / Color_Dio_Connected" Android: state_checked = "true" /> & Lt; Item Android: Drabbles = "@Drawable / Color_Dialog_OnScheduled" /> & Lt; / Selector & gt;  

Sets the status of a radio button to select any of the above pressed / focus states

Then, you can click on this button the background of a button Can be specified as such:

  & lt; RadioButton Android "Android: attr / borderlessButtonStyle" id = "@ + id / btn_network" style = Android: Layout_width = "Fill_parent" Android: Layout_height = "Wrap_content" Android: Layout_gravity = "Center_horizontal" android: background = "@ drawable / menu_background "android: button =" @ android: color / transparent "Android: drawableTop ="! @ drawable / color_radio_button & lt; - here - & gt; android: gravity = "center" Android: paddingBottom = "8dp" Android: paddingLeft = "8dp" Android: paddingRight = "8dp" Android: paddingTop = "14dp" Android: text = "@ string / network" Android : Textcolor = "@ drawable / Menu_btn_tekst_viit" android: text size = "14sp" / & gt;  

Comments