android - How to custom switch button? -


I would like to become as custom list button:

to

how to get it? Color and text change

You can use the following code: <> pre & lt; org.jraf.android.backport.switchwidget.Switch android: id = "@ + id / th" Android: Layout_width = "Match_parent" Android: Layout_height = "Wrap_content" app: thumb = "@ drawable / apptheme_switch_inner_holo_light" app: Track = "@ drawable / apptheme_switch_track_holo_light" app: textOn = "@ string / switch_yes" app: textOff = "@ string / switch_no" Android: textcolor = "# 000000" / & gt;

Create .xml in xml designated colors res / values ​​folder:

  & lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; Resources & gt; & Lt; Color name = "red" & gt; # Ff0000 & lt; / Color & gt; & Lt; Color name = "green" & gt; # 00ff00 & lt; / Color & gt; & Lt; / Resources & gt;  

In the drawable folder, to create an xml file my_btn_toggle.xml:

   & Lt; Item Android: state_checked = "true" android: drawable = "@ color / green" /> & Lt; / Selector & gt;  

And add your toggle button to define in the xml section:

  Android: background = "@ drawable / my_btn_toggle  

and textOff of the code

  to change the Android color: switchTextAppearance = "@ style / switch"  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -