Class Switch
- All Implemented Interfaces:
Drawable.Callback,ViewTreeObserver.OnPreDrawListener,Checkable,Checkable2
- Since:
- 3.12
-
Nested Class Summary
Nested classes/interfaces inherited from class icyllis.modernui.widget.TextView
TextView.BufferTypeNested classes/interfaces inherited from class icyllis.modernui.view.View
View.DragShadow, View.Focusable, View.FocusableMode, View.FocusDirection, View.FocusRealDirection, View.LayoutDir, View.NestedScrollType, View.OnAttachStateChangeListener, View.OnClickListener, View.OnContextClickListener, View.OnCreateContextMenuListener, View.OnDragListener, View.OnFocusChangeListener, View.OnGenericMotionListener, View.OnHoverListener, View.OnKeyListener, View.OnLayoutChangeListener, View.OnLongClickListener, View.OnScrollChangeListener, View.OnTouchListener, View.ResolvedLayoutDir, View.ScrollAxis, View.ScrollBarStyle, View.ScrollIndicators, View.TextAlignment, View.VisibilityNested classes/interfaces inherited from interface icyllis.modernui.widget.Checkable
Checkable.OnCheckedChangeListener -
Field Summary
Fields inherited from class icyllis.modernui.widget.TextView
UNKNOWN_BORINGFields inherited from class icyllis.modernui.view.View
ALPHA, BOTTOM, EMPTY_STATE_SET, ENABLED_FOCUSED_SELECTED_STATE_SET, ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, ENABLED_FOCUSED_STATE_SET, ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET, ENABLED_SELECTED_STATE_SET, ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET, ENABLED_STATE_SET, ENABLED_WINDOW_FOCUSED_STATE_SET, FOCUS_BACKWARD, FOCUS_DOWN, FOCUS_FORWARD, FOCUS_LEFT, FOCUS_RIGHT, FOCUS_UP, FOCUSABLE, FOCUSABLE_AUTO, FOCUSABLES_ALL, FOCUSABLES_TOUCH_MODE, FOCUSED_SELECTED_STATE_SET, FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, FOCUSED_STATE_SET, FOCUSED_WINDOW_FOCUSED_STATE_SET, GONE, HAPTIC_FEEDBACK_ENABLED, INVISIBLE, LAYOUT_DIRECTION_INHERIT, LAYOUT_DIRECTION_LOCALE, LAYOUT_DIRECTION_LTR, LAYOUT_DIRECTION_RTL, LAYOUT_DIRECTION_UNDEFINED, LEFT, MEASURED_HEIGHT_STATE_SHIFT, MEASURED_SIZE_MASK, MEASURED_STATE_MASK, MEASURED_STATE_TOO_SMALL, NO_ID, NOT_FOCUSABLE, OVER_SCROLL_ALWAYS, OVER_SCROLL_IF_CONTENT_SCROLLS, OVER_SCROLL_NEVER, PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET, PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_FOCUSED_STATE_SET, PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_SELECTED_STATE_SET, PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_STATE_SET, PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET, PRESSED_FOCUSED_SELECTED_STATE_SET, PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_FOCUSED_STATE_SET, PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET, PRESSED_SELECTED_STATE_SET, PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_STATE_SET, PRESSED_WINDOW_FOCUSED_STATE_SET, RIGHT, ROTATION, ROTATION_X, ROTATION_Y, SCALE_X, SCALE_Y, SCROLL_AXIS_HORIZONTAL, SCROLL_AXIS_NONE, SCROLL_AXIS_VERTICAL, SCROLL_INDICATOR_BOTTOM, SCROLL_INDICATOR_END, SCROLL_INDICATOR_LEFT, SCROLL_INDICATOR_RIGHT, SCROLL_INDICATOR_START, SCROLL_INDICATOR_TOP, SCROLL_X, SCROLL_Y, SCROLLBARS_INSIDE_INSET, SCROLLBARS_INSIDE_OVERLAY, SCROLLBARS_OUTSIDE_INSET, SCROLLBARS_OUTSIDE_OVERLAY, SELECTED_STATE_SET, SELECTED_WINDOW_FOCUSED_STATE_SET, SOUND_EFFECTS_ENABLED, TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_GRAVITY, TEXT_ALIGNMENT_INHERIT, TEXT_ALIGNMENT_TEXT_END, TEXT_ALIGNMENT_TEXT_START, TEXT_ALIGNMENT_VIEW_END, TEXT_ALIGNMENT_VIEW_START, TEXT_DIRECTION_ANY_RTL, TEXT_DIRECTION_FIRST_STRONG, TEXT_DIRECTION_FIRST_STRONG_LTR, TEXT_DIRECTION_FIRST_STRONG_RTL, TEXT_DIRECTION_INHERIT, TEXT_DIRECTION_LOCALE, TEXT_DIRECTION_LTR, TEXT_DIRECTION_RTL, TOP, TRANSLATION_X, TRANSLATION_Y, TRANSLATION_Z, TYPE_NON_TOUCH, TYPE_TOUCH, VIEW_MARKER, VISIBLE, WINDOW_FOCUSED_STATE_SET, X, Y, Z -
Constructor Summary
ConstructorsConstructorDescriptionConstruct a new Switch with default styling.Switch(Context context, AttributeSet attrs) Construct a new Switch with default styling, overriding specific style attributes as requested.Switch(Context context, AttributeSet attrs, ResourceId defStyleAttr) Construct a new Switch with a default style determined by the given theme attribute, overriding specific style attributes as requested.Switch(Context context, AttributeSet attrs, ResourceId defStyleAttr, ResourceId defStyleRes) Construct a new Switch with a default style determined by the given theme attribute or style resource, overriding specific style attributes as requested. -
Method Summary
Modifier and TypeMethodDescriptionvoidBase method that directly draws this view and its background, foreground, overlay and all children to the given canvas.voiddrawableHotspotChanged(float x, float y) This function is called whenever the view hotspot changes and needs to be propagated to drawables or child views managed by the view.protected voidThis function is called whenever the state of the view changes in such a way that it impacts the state of drawables being shown.intReturns the left padding of the view, plus space for the left Drawable if any.intReturns the right padding of the view, plus space for the right Drawable if any.booleanReturns whether the track should be split by the thumb.intGet the minimum width of the switch in pixels.intGet the amount of horizontal padding between the switch and the associated text.Returns the text for when the button is not in the checked state.Returns the text for when the button is in the checked state.Get the drawable used for the switch "thumb" - the piece that the user can physically touch and drag along the track.protected final floatGet the drawable used for the track that the switch slides within.final booleanGet the current checked state of the viewvoidCallDrawable.jumpToCurrentState()on all Drawable objects associated with this view.protected int[]onCreateDrawableState(int extraSpace) Generate the newDrawablestate for this view.protected voidDraw the content of this view, implement this to do your drawing.protected voidonLayout(boolean changed, int left, int top, int right, int bottom) Called fromView.layout(int, int, int, int)when this view should assign a size and position to each of its children.protected voidonMeasure(int widthMeasureSpec, int heightMeasureSpec) Measure the view and its content to determine the measured width and the measured height.booleanCall this view's OnClickListener, if it is defined.voidsetChecked(boolean checked) Change the checked state of the viewvoidRegister a callback to be invoked when the checked state of this button changes.voidsetSplitTrack(boolean splitTrack) Specifies whether the track should be split by the thumb.voidsetSwitchMinWidth(int pixels) Set the minimum width of the switch in pixels.voidsetSwitchPadding(int pixels) Set the amount of horizontal padding between the switch and the associated text.voidsetTextOff(CharSequence textOff) Sets the text for when the button is not in the checked state.voidsetTextOn(CharSequence textOn) Sets the text for when the button is in the checked state.voidsetThumbDrawable(Drawable thumb) Set the drawable used for the switch "thumb" - the piece that the user can physically touch and drag along the track.voidsetThumbTintBlendMode(BlendMode blendMode) Specifies the blending mode used to apply the tint specified bysetThumbTintList(ColorStateList)} to the thumb drawable.voidApplies a tint to the thumb drawable.voidsetTrackDrawable(Drawable track) Set the drawable used for the track that the switch slides within.voidsetTrackTintBlendMode(BlendMode blendMode) Specifies the blending mode used to apply the tint specified bysetTrackTintList(ColorStateList)} to the track drawable.voidApplies a tint to the track drawable.voidtoggle()Change the checked state of the view to the inverse of its current stateprotected booleanverifyDrawable(Drawable who) If your view subclass is displaying its own Drawable objects, it should override this function and return true for any Drawable it is displaying.Methods inherited from class icyllis.modernui.widget.TextView
addTextChangedListener, bringPointIntoView, cancelLongPress, computeHorizontalScrollRange, computeVerticalScrollExtent, computeVerticalScrollRange, didTouchFocusSelect, getAutoLinkMask, getBaseline, getCompoundDrawablePadding, getCompoundDrawables, getCompoundDrawablesRelative, getCompoundDrawableTintBlendMode, getCompoundDrawableTintList, getCompoundPaddingBottom, getCompoundPaddingEnd, getCompoundPaddingStart, getCompoundPaddingTop, getCurrentHintTextColor, getCurrentTextColor, getDefaultEditable, getDefaultMovementMethod, getEditableText, getEllipsize, getExtendedPaddingBottom, getExtendedPaddingTop, getFilters, getFirstBaselineToTopHeight, getFocusedRect, getGravity, getHighlightColor, getHint, getHintTextColors, getIncludeFontPadding, getLastBaselineToBottomHeight, getLayout, getLineBounds, getLineBreakStyle, getLineBreakWordStyle, getLineCount, getLineHeight, getLineSpacingAmount, getLineSpacingMultiplier, getLinksClickable, getLinkTextColors, getMaxHeight, getMaxLines, getMaxWidth, getMinHeight, getMinLines, getMinWidth, getMovementMethod, getOffsetForPosition, getPaint, getSelectionEnd, getSelectionStart, getText, getTextColors, getTextDirectionHeuristic, getTextLocale, getTextMetricsParams, getTextSize, getTextSizeUnit, getTextStyle, getTotalPaddingBottom, getTotalPaddingEnd, getTotalPaddingLeft, getTotalPaddingRight, getTotalPaddingStart, getTotalPaddingTop, getTransformationMethod, getTypeface, hasSelection, invalidateDrawable, isCursorVisible, isFallbackLineSpacing, isHorizontallyScrollable, isTextSelectable, makeNewLayout, moveCursorToVisibleOffset, onAttachedToWindow, onCreateContextMenu, onDetachedFromWindow, onFocusChanged, onGenericMotionEvent, onKeyDown, onKeyShortcut, onKeyUp, onPreDraw, onResolvePointerIcon, onRtlPropertiesChanged, onTextChanged, onTextContextMenuItem, onTouchEvent, removeTextChangedListener, setAutoLinkMask, setCompoundDrawablePadding, setCompoundDrawables, setCompoundDrawablesRelative, setCompoundDrawablesRelativeWithIntrinsicBounds, setCompoundDrawablesWithIntrinsicBounds, setCompoundDrawableTintBlendMode, setCompoundDrawableTintList, setCursorVisible, setEditableFactory, setEllipsize, setEnabled, setFallbackLineSpacing, setFilters, setFirstBaselineToTopHeight, setGravity, setHeight, setHighlightColor, setHint, setHintTextColor, setHintTextColor, setHorizontallyScrolling, setIncludeFontPadding, setLastBaselineToBottomHeight, setLineBreakStyle, setLineBreakWordStyle, setLineHeight, setLineHeight, setLines, setLineSpacing, setLinksClickable, setLinkTextColor, setLinkTextColor, setMaxHeight, setMaxLines, setMaxWidth, setMinHeight, setMinLines, setMinWidth, setMovementMethod, setPadding, setPaddingRelative, setSelectAllOnFocus, setSingleLine, setSingleLine, setSpannableFactory, setText, setText, setTextAppearance, setTextAppearance, setTextColor, setTextColor, setTextIsSelectable, setTextKeepState, setTextKeepState, setTextLocale, setTextMetricsParams, setTextSize, setTextSize, setTextStyle, setTransformationMethod, setTypeface, setWidth, showContextMenuMethods inherited from class icyllis.modernui.view.View
addFocusables, addFocusables, addKeyboardNavigationClusters, addOnAttachStateChangeListener, addOnLayoutChangeListener, addTouchables, awakenScrollBars, awakenScrollBars, callOnClick, cancelPendingInputEvents, canReceivePointerEvents, canResolveLayoutDirection, canResolveTextAlignment, canResolveTextDirection, canScrollHorizontally, canScrollVertically, clearFocus, combineMeasuredStates, computeHorizontalScrollExtent, computeHorizontalScrollOffset, computeScroll, computeVerticalScrollOffset, createContextMenu, dispatchDraw, dispatchDrawableHotspotChanged, dispatchFinishTemporaryDetach, dispatchGenericMotionEvent, dispatchGenericPointerEvent, dispatchHoverEvent, dispatchKeyEvent, dispatchKeyShortcutEvent, dispatchNestedFling, dispatchNestedPreFling, dispatchNestedPreScroll, dispatchNestedScroll, dispatchPointerEvent, dispatchSetActivated, dispatchSetPressed, dispatchSetSelected, dispatchStartTemporaryDetach, dispatchTouchEvent, dispatchVisibilityChanged, dispatchWindowFocusChanged, dispatchWindowVisibilityChanged, dp, findFocus, findViewById, findViewByPredicate, findViewByPredicateInsideOut, findViewWithTag, focusSearch, forceHasOverlappingRendering, forceLayout, generateViewId, getAlpha, getAnimationMatrix, getBackground, getBottom, getBoundsOnScreen, getBoundsOnScreen, getClipBounds, getClipBounds, getContentDescription, getContext, getContextMenuInfo, getDefaultSize, getDrawableState, getDrawingRect, getElevation, getFadingEdge, getFadingEdgeLength, getFocusable, getFocusables, getForeground, getForegroundGravity, getGlobalVisibleRect, getGlobalVisibleRect, getHandler, getHasOverlappingRendering, getHeight, getHitRect, getHorizontalScrollbarHeight, getHorizontalScrollbarThumbDrawable, getHorizontalScrollbarTrackDrawable, getId, getInverseMatrix, getKeyDispatcherState, getLayoutDirection, getLayoutParams, getLeft, getLocalVisibleRect, getLocationInWindow, getLocationOnScreen, getMatrix, getMeasuredHeight, getMeasuredHeightAndState, getMeasuredState, getMeasuredWidth, getMeasuredWidthAndState, getMinimumHeight, getMinimumWidth, getNextClusterForwardId, getNextFocusDownId, getNextFocusForwardId, getNextFocusLeftId, getNextFocusRightId, getNextFocusUpId, getOnFocusChangeListener, getOnLongClickListener, getOutlineProvider, getOverScrollMode, getPaddingBottom, getPaddingEnd, getPaddingLeft, getPaddingRight, getPaddingStart, getPaddingTop, getParent, getPivotX, getPivotY, getRawLayoutDirection, getRawTextAlignment, getRawTextDirection, getRevealOnFocusHint, getRight, getRootView, getRotation, getRotationX, getRotationY, getScaleX, getScaleY, getScrollBarDefaultDelayBeforeFade, getScrollBarFadeDuration, getScrollBarSize, getScrollBarStyle, getScrollIndicators, getScrollX, getScrollY, getStateDescription, getStateListAnimator, getSuggestedMinimumHeight, getSuggestedMinimumWidth, getTag, getTag, getTextAlignment, getTextDirection, getTooltipText, getTooltipView, getTop, getTouchables, getTransitionAlpha, getTransitionName, getTranslationX, getTranslationY, getTranslationZ, getVerticalFadingEdgeLength, getVerticalScrollbarThumbDrawable, getVerticalScrollbarTrackDrawable, getVerticalScrollbarWidth, getViewRoot, getViewTreeObserver, getVisibility, getWidth, getWindowAttachCount, getWindowVisibility, getX, getY, getZ, handleScrollBarDragging, hasExplicitFocusable, hasFocus, hasFocusable, hasIdentityMatrix, hasNestedScrollingParent, hasOnClickListeners, hasOnLongClickListeners, hasOverlappingRendering, hasTransientState, hasTranslationTransientState, hasWindowFocus, invalidate, invalidate, invalidate, invalidateOutline, isActivated, isAttachedToWindow, isClickable, isContextClickable, isDuplicateParentStateEnabled, isEnabled, isFocusable, isFocusableInTouchMode, isFocused, isFocusedByDefault, isForegroundInsidePadding, isHapticFeedbackEnabled, isHorizontalFadingEdgeEnabled, isHorizontalScrollBarEnabled, isHovered, isInLayout, isInScrollingContainer, isInTouchMode, isKeyboardNavigationCluster, isLaidOut, isLayoutDirectionInherited, isLayoutDirectionResolved, isLayoutRequested, isLayoutRtl, isLongClickable, isNestedScrollingEnabled, isPaddingRelative, isPivotSet, isPressed, isRootNamespace, isScrollbarFadingEnabled, isSelected, isShowingLayoutBounds, isShown, isSoundEffectsEnabled, isTemporarilyDetached, isTextAlignmentInherited, isTextAlignmentResolved, isTextDirectionInherited, isTextDirectionResolved, isVerticalFadingEdgeEnabled, isVerticalScrollBarEnabled, isVerticalScrollBarHidden, keyboardNavigationClusterSearch, layout, mapRectFromViewToScreenCoords, measure, mergeDrawableStates, offsetLeftAndRight, offsetTopAndBottom, onCancelPendingInputEvents, onDragEvent, onDrawForeground, onDrawScrollBars, onFinishTemporaryDetach, onHoverChanged, onHoverEvent, onOverScrolled, onScrollChanged, onSizeChanged, onStartTemporaryDetach, onVisibilityAggregated, onVisibilityChanged, onWindowFocusChanged, onWindowVisibilityChanged, overScrollBy, performButtonActionOnTouchDown, performContextClick, performContextClick, performHapticFeedback, performHapticFeedback, performLongClick, performLongClick, playSoundEffect, pointInView, post, postDelayed, postInvalidate, postInvalidateDelayed, postInvalidateOnAnimation, postOnAnimation, postOnAnimationDelayed, refreshDrawableState, removeCallbacks, removeOnAttachStateChangeListener, removeOnLayoutChangeListener, requestFocus, requestFocus, requestFocus, requestLayout, requestRectangleOnScreen, requestRectangleOnScreen, requireViewById, resetPivot, resetResolvedDrawables, resolveDrawables, resolveLayoutDirection, resolveLayoutParams, resolvePadding, resolveRtlPropertiesIfNeeded, resolveSize, resolveSizeAndState, resolveTextAlignment, resolveTextDirection, restoreDefaultFocus, scheduleDrawable, scrollBy, scrollTo, setActivated, setAlpha, setAnimationMatrix, setBackground, setBottom, setClickable, setClipBounds, setContentDescription, setContextClickable, setDuplicateParentStateEnabled, setElevation, setFocusable, setFocusable, setFocusableInTouchMode, setFocusedByDefault, setFocusedInCluster, setForeground, setForegroundGravity, setFrame, setHapticFeedbackEnabled, setHasTransientState, setHasTranslationTransientState, setHorizontalFadingEdgeEnabled, setHorizontalScrollBarEnabled, setHorizontalScrollbarThumbDrawable, setHorizontalScrollbarTrackDrawable, setHovered, setId, setIsRootNamespace, setKeyboardNavigationCluster, setLayoutDirection, setLayoutParams, setLeft, setLongClickable, setMeasuredDimension, setMinimumHeight, setMinimumWidth, setNestedScrollingEnabled, setNextClusterForwardId, setNextFocusDownId, setNextFocusForwardId, setNextFocusLeftId, setNextFocusRightId, setNextFocusUpId, setOnClickListener, setOnContextClickListener, setOnCreateContextMenuListener, setOnDragListener, setOnFocusChangeListener, setOnGenericMotionListener, setOnHoverListener, setOnKeyListener, setOnLongClickListener, setOnScrollChangeListener, setOnTouchListener, setOutlineProvider, setOverScrollMode, setPivotX, setPivotY, setPressed, setRevealOnFocusHint, setRight, setRotation, setRotationX, setRotationY, setScaleX, setScaleY, setScrollBarDefaultDelayBeforeFade, setScrollBarFadeDuration, setScrollbarFadingEnabled, setScrollBarSize, setScrollBarStyle, setScrollIndicators, setScrollIndicators, setScrollX, setScrollY, setSelected, setSoundEffectsEnabled, setStateDescription, setStateListAnimator, setTag, setTag, setTextAlignment, setTextDirection, setTooltipText, setTop, setTransitionAlpha, setTransitionName, setTransitionVisibility, setTranslationX, setTranslationY, setTranslationZ, setVerticalFadingEdgeEnabled, setVerticalScrollBarEnabled, setVerticalScrollbarThumbDrawable, setVerticalScrollbarTrackDrawable, setVisibility, setWillNotDraw, setX, setY, setZ, showContextMenu, sp, startActionMode, startActionMode, startDragAndDrop, startNestedScroll, stopNestedScroll, toGlobalMotionEvent, toLocalMotionEvent, toString, transformFromViewToWindowSpace, transformMatrixToGlobal, transformMatrixToLocal, unscheduleDrawable, unscheduleDrawable, willNotDrawMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface icyllis.modernui.widget.Checkable2
getId
-
Constructor Details
-
Switch
Construct a new Switch with default styling.- Parameters:
context- The Context that will determine this widget's theming.
-
Switch
Construct a new Switch with default styling, overriding specific style attributes as requested.- Parameters:
context- The Context that will determine this widget's theming.attrs- Specification of attributes that should deviate from default styling.
-
Switch
public Switch(Context context, @Nullable AttributeSet attrs, @Nullable @AttrRes ResourceId defStyleAttr) Construct a new Switch with a default style determined by the given theme attribute, overriding specific style attributes as requested.- Parameters:
context- The Context that will determine this widget's theming.attrs- Specification of attributes that should deviate from the default styling.defStyleAttr- An attribute in the current theme that contains a reference to a style resource that supplies default values for the view. Can be null to not look for defaults.
-
Switch
public Switch(Context context, @Nullable AttributeSet attrs, @Nullable @AttrRes ResourceId defStyleAttr, @Nullable @StyleRes ResourceId defStyleRes) Construct a new Switch with a default style determined by the given theme attribute or style resource, overriding specific style attributes as requested.- Parameters:
context- The Context that will determine this widget's theming.attrs- Specification of attributes that should deviate from the default styling.defStyleAttr- An attribute in the current theme that contains a reference to a style resource that supplies default values for the view. Can be null to not look for defaults.defStyleRes- A resource identifier of a style resource that supplies default values for the view, used only if defStyleAttr is 0 or can not be found in the theme. Can be null to not look for defaults.
-
-
Method Details
-
setSwitchPadding
public void setSwitchPadding(int pixels) Set the amount of horizontal padding between the switch and the associated text.- Parameters:
pixels- Amount of padding in pixels
-
getSwitchPadding
public int getSwitchPadding()Get the amount of horizontal padding between the switch and the associated text.- Returns:
- Amount of padding in pixels
-
setSwitchMinWidth
public void setSwitchMinWidth(int pixels) Set the minimum width of the switch in pixels. The switch's width will be the maximum of this value and its measured width as determined by the switch drawables and text used.- Parameters:
pixels- Minimum width of the switch in pixels
-
getSwitchMinWidth
public int getSwitchMinWidth()Get the minimum width of the switch in pixels. The switch's width will be the maximum of this value and its measured width as determined by the switch drawables and text used.- Returns:
- Minimum width of the switch in pixels
-
setTrackDrawable
Set the drawable used for the track that the switch slides within.- Parameters:
track- Track drawable
-
getTrackDrawable
Get the drawable used for the track that the switch slides within.- Returns:
- Track drawable
-
setTrackTintList
Applies a tint to the track drawable. Does not modify the current tint mode, which isBlendMode.SRC_INby default.Subsequent calls to
setTrackDrawable(Drawable)will automatically mutate the drawable and apply the specified tint and tint mode usingDrawable.setTintList(ColorStateList).- Parameters:
tint- the tint to apply, may benullto clear tint- See Also:
-
getTrackTintList
- Returns:
- the tint applied to the track drawable
- See Also:
-
setTrackTintBlendMode
Specifies the blending mode used to apply the tint specified bysetTrackTintList(ColorStateList)} to the track drawable. The default mode isBlendMode.SRC_IN.- Parameters:
blendMode- the blending mode used to apply the tint, may benullto clear tint- See Also:
-
getTrackTintBlendMode
- Returns:
- the blending mode used to apply the tint to the track drawable
- See Also:
-
setThumbDrawable
Set the drawable used for the switch "thumb" - the piece that the user can physically touch and drag along the track.- Parameters:
thumb- Thumb drawable
-
getThumbDrawable
Get the drawable used for the switch "thumb" - the piece that the user can physically touch and drag along the track.- Returns:
- Thumb drawable
-
setThumbTintList
Applies a tint to the thumb drawable. Does not modify the current tint mode, which isBlendMode.SRC_INby default.Subsequent calls to
setThumbDrawable(Drawable)will automatically mutate the drawable and apply the specified tint and tint mode usingDrawable.setTintList(ColorStateList).- Parameters:
tint- the tint to apply, may benullto clear tint- See Also:
-
getThumbTintList
- Returns:
- the tint applied to the thumb drawable
- See Also:
-
setThumbTintBlendMode
Specifies the blending mode used to apply the tint specified bysetThumbTintList(ColorStateList)} to the thumb drawable. The default mode isBlendMode.SRC_IN.- Parameters:
blendMode- the blending mode used to apply the tint, may benullto clear tint- See Also:
-
getThumbTintBlendMode
- Returns:
- the blending mode used to apply the tint to the thumb drawable
- See Also:
-
setSplitTrack
public void setSplitTrack(boolean splitTrack) Specifies whether the track should be split by the thumb. When true, the thumb's optical bounds will be clipped out of the track drawable, then the thumb will be drawn into the resulting gap.- Parameters:
splitTrack- Whether the track should be split by the thumb
-
getSplitTrack
public boolean getSplitTrack()Returns whether the track should be split by the thumb. -
getTextOn
Returns the text for when the button is in the checked state.- Returns:
- The text.
-
setTextOn
Sets the text for when the button is in the checked state. If not null, it overrides the text previously set byTextView.setText(java.lang.CharSequence).- Parameters:
textOn- The text.
-
getTextOff
Returns the text for when the button is not in the checked state.- Returns:
- The text.
-
setTextOff
Sets the text for when the button is not in the checked state. If not null, it overrides the text previously set byTextView.setText(java.lang.CharSequence).- Parameters:
textOff- The text.
-
onMeasure
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) Description copied from class:ViewMeasure the view and its content to determine the measured width and the measured height. This method is invoked byView.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 anIllegalStateException, thrown byView.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:
onMeasurein classTextView- Parameters:
widthMeasureSpec- width measure specification imposed by the parentMeasureSpecheightMeasureSpec- height measure specification imposed by the parentMeasureSpec
-
getThumbPosition
- Returns:
- the current thumb position as a decimal value between 0 (off) and 1 (on).
-
toggle
public void toggle()Description copied from interface:CheckableChange the checked state of the view to the inverse of its current state -
performClick
public boolean performClick()Description copied from class:ViewCall this view's OnClickListener, if it is defined. Performs all normal actions associated with clicking: reporting accessibility event, playing a sound, etc.- Overrides:
performClickin classView- Returns:
- True there was an assigned OnClickListener that was called, false otherwise is returned.
-
isChecked
public final boolean isChecked()Description copied from interface:CheckableGet the current checked state of the view -
setChecked
public void setChecked(boolean checked) Description copied from interface:CheckableChange the checked state of the view- Specified by:
setCheckedin interfaceCheckable- Parameters:
checked- The new checked state
-
setOnCheckedChangeListener
Register a callback to be invoked when the checked state of this button changes.- Specified by:
setOnCheckedChangeListenerin interfaceCheckable2- Parameters:
listener- the callback to call on checked state change
-
onLayout
protected void onLayout(boolean changed, int left, int top, int right, int bottom) Description copied from class:ViewCalled fromView.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.
-
draw
Description copied from class:ViewBase method that directly draws this view and its background, foreground, overlay and all children to the given canvas. When implementing a view, overrideView.onDraw(Canvas)instead of this.This is not the entry point for the view system to draw.
-
onDraw
Description copied from class:ViewDraw 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.
-
getCompoundPaddingLeft
public int getCompoundPaddingLeft()Description copied from class:TextViewReturns the left padding of the view, plus space for the left Drawable if any.- Overrides:
getCompoundPaddingLeftin classTextView
-
getCompoundPaddingRight
public int getCompoundPaddingRight()Description copied from class:TextViewReturns the right padding of the view, plus space for the right Drawable if any.- Overrides:
getCompoundPaddingRightin classTextView
-
onCreateDrawableState
Description copied from class:ViewGenerate the newDrawablestate for this view. This is called by the view system when the cached Drawable state is determined to be invalid. To retrieve the current state, you should useView.getDrawableState().- Overrides:
onCreateDrawableStatein classTextView- Parameters:
extraSpace- if non-zero, this is the number of extra entries you would like in the returned array in which you can place your own states.- Returns:
- an array holding the current
Drawablestate of the view. - See Also:
-
drawableStateChanged
protected void drawableStateChanged()Description copied from class:ViewThis function is called whenever the state of the view changes in such a way that it impacts the state of drawables being shown.If the View has a StateListAnimator, it will also be called to run necessary state change animations.
Be sure to call through to the superclass when overriding this function.
- Overrides:
drawableStateChangedin classTextView- See Also:
-
drawableHotspotChanged
public void drawableHotspotChanged(float x, float y) Description copied from class:ViewThis function is called whenever the view hotspot changes and needs to be propagated to drawables or child views managed by the view.Dispatching to child views is handled by
View.dispatchDrawableHotspotChanged(float, float).Be sure to call through to the superclass when overriding this function.
- Overrides:
drawableHotspotChangedin classTextView- Parameters:
x- hotspot x coordinatey- hotspot y coordinate
-
verifyDrawable
Description copied from class:ViewIf your view subclass is displaying its own Drawable objects, it should override this function and return true for any Drawable it is displaying. This allows animations for those drawables to be scheduled.Be sure to call through to the super class when overriding this function.
- Overrides:
verifyDrawablein classTextView- Parameters:
who- The Drawable to verify. Return true if it is one you are displaying, else return the result of calling through to the super class.- Returns:
- boolean If true then the Drawable is being displayed in the view; else false and it is not allowed to animate.
- See Also:
-
jumpDrawablesToCurrentState
public void jumpDrawablesToCurrentState()Description copied from class:ViewCallDrawable.jumpToCurrentState()on all Drawable objects associated with this view.Also calls
StateListAnimator.jumpToCurrentState()if there is a StateListAnimator attached to this view.- Overrides:
jumpDrawablesToCurrentStatein classTextView
-