Skip to main content

Posts

Showing posts with the label setchecked

Custom Toggle Button in ANDROID

Toggle Button is a special button that has two states  for eg :"on" and "off".It can be an alternative to Radio Buttons. Method to create a Custom Toggle Button is given below : in custom_btn.xml in style.xml : in custom_toggle_bg.xml : in custom_toggle_btn.xml :                                              

Toggle button in ANDROID - An alternative to radio button

Toggle Button is a special button that has two states  for eg :"on" and "off".It can be an alternative to Radio Buttons. Below are some methods mentioned in this example : setOnClickListener – Used to register a callback whenever view is clicked setChecked() – used to mark toggle button as checked/unchecked setTextOn() – used to display text on toggle button whenever it is CHECKED setTextOff() – used to display text on toggle button whenever it is UnCHECKED. public class MainActivity extends Activity { ToggleButton toggle; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); toggle = (ToggleButton) findViewById(R.id.togglebut); // you can set text accordingly when checked or not toggle.setTextOn("Toggle is Checked"); toggle.setTextOff("Toggle is not Checked"); // you can set if toggle to be checked or not toggle.setChecked(true); t...