image1 image2 image3

HELLO I'M NITENDRA THAKUR|WELCOME TO MY PERSONAL BLOG|I LOVE TO DO CREATIVE THINGS|I'M PROFESSIONAL ANDROID APPLICATION DEVELOPER

how to use Toggle Button in android programming?



1.ToggleButton

ToggleButton allows user to change a setting between two states.It displays checked/unchecked states as a button with a "light" indicator and by default accompanied with the text "ON" or "OFF".


You can add a basic toggle button to your layout with theToggleButton object. Android 4.0 (API level 14) introduces another kind of toggle button called a switch that provides a slider control, which you can add with a Switch object.

ToggleButton and Switch controls are subclasses of CompoundButton and function in the same manner, so you can implement their behavior the same way.


In both the above controls user receives an onclick-event every time user select the controls.


Note : ToggleButton extends Compondbutton

2. XML attributes of ToggleButton

android:disabledAlpha  :  The alpha to apply to the indicator when disabled.
android:textOff              :  The text for the button when it is not checked.
android:textOn              : The text for the button when it is checked.

3.Methods of ToggleButton


  • public CharSequence getTextOff() method returns the text for when the button is not in the checked state.
  • public CharSequence getTextOn() method returns the text for when the button is in the checked state
  • public void onIntializedAccessibilityEvent(AccessibiltyEvent event) called when the source of an accessibility event is the view whose state change triggered firing the event.
  • public void onIntializedAccessibilityNodeInfo(AccessibilityNodeInfo info) called to initialize an AccessibilityNodeInfo with information about the view. the base implementation sets :
  1. setParent(View),
  2. setBoundsInParent(Rect),
  3. setBoundsInScreen(Rect),
  4. setPackageName(CharSequence),
  5. setClassName(CharSequence),
  6. setContentDescription(CharSequence),
  7. setEnabled(boolean),
  8. setClickable(boolean),
  9. setFocusable(boolean),
  10. setFocused(boolean),
  11. setLongClickable(boolean),
  12. setSelected(boolean),

  • public void setBackgroundDrawable(Drawable d) method is depricated use setBackground(Drawable) instead
  • public void setChecked(boolean checked) method changes the checked state of the button.
  • public void setTextOff(CharSequence textOff) method set the text for when button is in not checked state
  • public void setTextOn(CharSequence textOn) method set the text when but is in checked state.
  • protected void drawableStateChanged() method called when the state of the view changes in such a way that it impacts the state of drawables being shown.
  • protected void onFinishInflate() method finalize the inflating view from XML.

4.Download ToggleButton Example : ToggleButtonDemo.zip

Share this:

CONVERSATION

0 comments:

Post a Comment