Class SwitchButton

All Implemented Interfaces:
Drawable.Callback, ViewTreeObserver.OnPreDrawListener, Checkable

public class SwitchButton extends CompoundButton
  • Constructor Details

    • SwitchButton

      public SwitchButton(Context context)
  • Method Details

    • onMeasure

      protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
      Description copied from class: View
      Measure the view and its content to determine the measured width and the measured height. This method is invoked by View.measure(int, int) and should be overridden by subclasses to provide accurate and efficient measurement of their contents.

      CONTRACT: When overriding this method, you must call View.setMeasuredDimension(int, int) to store the measured width and height of this view. Failure to do so will trigger an IllegalStateException, thrown by View.measure(int, int). Calling super.onMeasure() is a valid use.

      The base class implementation of measure defaults to the background size, unless a larger size is allowed by the MeasureSpec. Subclasses should override the base one to provide better measurements of their content.

      Overrides:
      onMeasure in class TextView
      Parameters:
      widthMeasureSpec - width measure specification imposed by the parent MeasureSpec
      heightMeasureSpec - height measure specification imposed by the parent MeasureSpec
    • onLayout

      protected void onLayout(boolean changed, int left, int top, int right, int bottom)
      Description copied from class: View
      Called from View.layout(int, int, int, int) when this view should assign a size and position to each of its children.

      Derived classes with children should override this method and call layout on each of their children.

      Overrides:
      onLayout in class TextView
      Parameters:
      changed - This is a new size or position for this view
      left - Left position, relative to parent
      top - Top position, relative to parent
      right - Right position, relative to parent
      bottom - Bottom position, relative to parent
    • onDraw

      protected void onDraw(@Nonnull Canvas canvas)
      Description copied from class: View
      Draw the content of this view, implement this to do your drawing.

      Note that (0, 0) will be the top left of the bounds, and (width, height) will be the bottom right of the bounds.

      Overrides:
      onDraw in class CompoundButton
      Parameters:
      canvas - the canvas to draw content
    • setChecked

      public void setChecked(boolean checked)
      Description copied from interface: Checkable
      Change the checked state of the view
      Specified by:
      setChecked in interface Checkable
      Overrides:
      setChecked in class CompoundButton
      Parameters:
      checked - The new checked state
    • setCheckedColor

      public void setCheckedColor(int checkedColor)
    • setUncheckedColor

      public void setUncheckedColor(int uncheckedColor)
    • setBorderWidth

      public void setBorderWidth(int borderWidth)