public class SwitchCompat extends CompoundButton
A Switch is a two-state toggle switch widget that can select between two
options. The user may drag the "thumb" back and forth to choose the selected option,
or simply tap to toggle as if it were a checkbox. The text
property controls the text displayed in the label for the switch, whereas the
off
and on
text
controls the text on the thumb. Similarly, the
textAppearance
and the related
setTypeface() methods control the typeface and style of label text, whereas the
switchTextAppearance
and
the related setSwitchTypeface() methods control that of the thumb.
See the Toggle Buttons guide.
CompoundButton.OnCheckedChangeListener
TextView.BufferType, TextView.OnEditorActionListener
View.AccessibilityDelegate, View.BaseSavedState, View.DragShadowBuilder, View.DrawingCacheQuality, View.FindViewFlags, View.FocusableMode, View.FocusDirection, View.FocusRealDirection, View.LayoutDir, View.MeasureSpec, View.OnApplyWindowInsetsListener, 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.OnSystemUiVisibilityChangeListener, View.OnTouchListener, View.ResolvedLayoutDir, View.ScrollBarStyle, View.ScrollIndicators, View.TextAlignment, View.Visibility
ACCESSIBILITY_CURSOR_POSITION_UNDEFINED, ACCESSIBILITY_LIVE_REGION_ASSERTIVE, ACCESSIBILITY_LIVE_REGION_NONE, ACCESSIBILITY_LIVE_REGION_POLITE, ALPHA, DEBUG_LAYOUT_PROPERTY, DRAG_FLAG_GLOBAL, DRAG_FLAG_GLOBAL_PERSISTABLE_URI_PERMISSION, DRAG_FLAG_GLOBAL_PREFIX_URI_PERMISSION, DRAG_FLAG_GLOBAL_URI_READ, DRAG_FLAG_GLOBAL_URI_WRITE, DRAG_FLAG_OPAQUE, DRAWING_CACHE_QUALITY_AUTO, DRAWING_CACHE_QUALITY_HIGH, DRAWING_CACHE_QUALITY_LOW, 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, FIND_VIEWS_WITH_ACCESSIBILITY_NODE_PROVIDERS, FIND_VIEWS_WITH_CONTENT_DESCRIPTION, FIND_VIEWS_WITH_TEXT, FOCUS_BACKWARD, FOCUS_DOWN, FOCUS_FORWARD, FOCUS_LEFT, FOCUS_RIGHT, FOCUS_UP, 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, IMPORTANT_FOR_ACCESSIBILITY_AUTO, IMPORTANT_FOR_ACCESSIBILITY_NO, IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS, IMPORTANT_FOR_ACCESSIBILITY_YES, INVISIBLE, KEEP_SCREEN_ON, LAYER_TYPE_HARDWARE, LAYER_TYPE_NONE, LAYER_TYPE_SOFTWARE, LAYOUT_DIRECTION_INHERIT, LAYOUT_DIRECTION_LOCALE, LAYOUT_DIRECTION_LTR, LAYOUT_DIRECTION_RTL, LAYOUT_DIRECTION_UNDEFINED, mAttributes, mBottom, mCachingFailed, mContext, mCurrentAnimation, mDebugViewAttributes, MEASURED_HEIGHT_STATE_SHIFT, MEASURED_SIZE_MASK, MEASURED_STATE_MASK, MEASURED_STATE_TOO_SMALL, mInputEventConsistencyVerifier, mLayoutParams, mLeft, mPaddingBottom, mPaddingLeft, mPaddingRight, mPaddingTop, mParent, mRight, mScrollX, mScrollY, mTag, mTop, mUserPaddingBottom, mUserPaddingLeft, mUserPaddingRight, NAVIGATION_BAR_TRANSIENT, NAVIGATION_BAR_TRANSLUCENT, NAVIGATION_BAR_TRANSPARENT, NAVIGATION_BAR_UNHIDE, NO_ID, 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, PUBLIC_STATUS_BAR_VISIBILITY_MASK, ROTATION, ROTATION_X, ROTATION_Y, SCALE_X, SCALE_Y, SCREEN_STATE_OFF, SCREEN_STATE_ON, 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, SCROLLBAR_POSITION_DEFAULT, SCROLLBAR_POSITION_LEFT, SCROLLBAR_POSITION_RIGHT, SCROLLBARS_INSIDE_INSET, SCROLLBARS_INSIDE_OVERLAY, SCROLLBARS_OUTSIDE_INSET, SCROLLBARS_OUTSIDE_OVERLAY, SELECTED_STATE_SET, SELECTED_WINDOW_FOCUSED_STATE_SET, SOUND_EFFECTS_ENABLED, sPreserveMarginParamsInLayoutParamConversion, STATUS_BAR_DISABLE_BACK, STATUS_BAR_DISABLE_CLOCK, STATUS_BAR_DISABLE_EXPAND, STATUS_BAR_DISABLE_HOME, STATUS_BAR_DISABLE_NOTIFICATION_ALERTS, STATUS_BAR_DISABLE_NOTIFICATION_ICONS, STATUS_BAR_DISABLE_NOTIFICATION_TICKER, STATUS_BAR_DISABLE_RECENT, STATUS_BAR_DISABLE_SEARCH, STATUS_BAR_DISABLE_SYSTEM_INFO, STATUS_BAR_HIDDEN, STATUS_BAR_TRANSIENT, STATUS_BAR_TRANSLUCENT, STATUS_BAR_TRANSPARENT, STATUS_BAR_UNHIDE, STATUS_BAR_VISIBLE, SYSTEM_UI_CLEARABLE_FLAGS, SYSTEM_UI_FLAG_FULLSCREEN, SYSTEM_UI_FLAG_HIDE_NAVIGATION, SYSTEM_UI_FLAG_IMMERSIVE, SYSTEM_UI_FLAG_IMMERSIVE_STICKY, SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN, SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION, SYSTEM_UI_FLAG_LAYOUT_STABLE, SYSTEM_UI_FLAG_LIGHT_STATUS_BAR, SYSTEM_UI_FLAG_LOW_PROFILE, SYSTEM_UI_FLAG_VISIBLE, SYSTEM_UI_LAYOUT_FLAGS, SYSTEM_UI_TRANSPARENT, 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, TRANSLATION_X, TRANSLATION_Y, TRANSLATION_Z, VIEW_LOG_TAG, VISIBLE, WINDOW_FOCUSED_STATE_SET, X, Y, Z
Constructor and Description |
---|
SwitchCompat(Context context)
Construct a new Switch with default styling.
|
SwitchCompat(Context context,
AttributeSet attrs)
Construct a new Switch with default styling, overriding specific style
attributes as requested.
|
SwitchCompat(Context context,
AttributeSet attrs,
int defStyleAttr)
Construct a new Switch with a default style determined by the given theme attribute,
overriding specific style attributes as requested.
|
Modifier and Type | Method and Description |
---|---|
void |
draw(Canvas c)
Manually render this view (and all of its children) to the given Canvas.
|
void |
drawableHotspotChanged(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 void |
drawableStateChanged()
This function is called whenever the state of the view changes in such
a way that it impacts the state of drawables being shown.
|
int |
getCompoundPaddingLeft()
Returns the left padding of the view, plus space for the left
Drawable if any.
|
int |
getCompoundPaddingRight()
Returns the right padding of the view, plus space for the right
Drawable if any.
|
boolean |
getShowText() |
boolean |
getSplitTrack()
Returns whether the track should be split by the thumb.
|
int |
getSwitchMinWidth()
Get the minimum width of the switch in pixels.
|
int |
getSwitchPadding()
Get the amount of horizontal padding between the switch and the associated text.
|
CharSequence |
getTextOff()
Returns the text displayed when the button is not in the checked state.
|
CharSequence |
getTextOn()
Returns the text displayed when the button is in the checked state.
|
Drawable |
getThumbDrawable()
Get the drawable used for the switch "thumb" - the piece that the user
can physically touch and drag along the track.
|
int |
getThumbTextPadding()
Get the horizontal padding around the text drawn on the switch itself.
|
ColorStateList |
getThumbTintList() |
PorterDuff.Mode |
getThumbTintMode() |
Drawable |
getTrackDrawable()
Get the drawable used for the track that the switch slides within.
|
ColorStateList |
getTrackTintList() |
PorterDuff.Mode |
getTrackTintMode() |
void |
jumpDrawablesToCurrentState()
Call
Drawable.jumpToCurrentState()
on all Drawable objects associated with this view. |
protected int[] |
onCreateDrawableState(int extraSpace)
Generate the new
Drawable state for
this view. |
protected void |
onDraw(Canvas canvas)
Implement this to do your drawing.
|
void |
onInitializeAccessibilityEvent(AccessibilityEvent event)
Initializes an
AccessibilityEvent with information about
this View which is the event source. |
void |
onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info)
Initializes an
AccessibilityNodeInfo with information about this view. |
protected void |
onLayout(boolean changed,
int left,
int top,
int right,
int bottom)
Called from layout when this view should
assign a size and position to each of its children.
|
void |
onMeasure(int widthMeasureSpec,
int heightMeasureSpec)
Measure the view and its content to determine the measured width and the
measured height.
|
void |
onPopulateAccessibilityEvent(AccessibilityEvent event)
Called from
View.dispatchPopulateAccessibilityEvent(AccessibilityEvent)
giving a chance to this View to populate the accessibility event with its
text content. |
boolean |
onTouchEvent(MotionEvent ev)
Implement this method to handle touch screen motion events.
|
void |
setChecked(boolean checked)
Changes the checked state of this button.
|
void |
setShowText(boolean showText)
Sets whether the on/off text should be displayed.
|
void |
setSplitTrack(boolean splitTrack)
Specifies whether the track should be split by the thumb.
|
void |
setSwitchMinWidth(int pixels)
Set the minimum width of the switch in pixels.
|
void |
setSwitchPadding(int pixels)
Set the amount of horizontal padding between the switch and the associated text.
|
void |
setSwitchTextAppearance(Context context,
int resid)
Sets the switch text color, size, style, hint color, and highlight color
from the specified TextAppearance resource.
|
void |
setSwitchTypeface(Typeface tf)
Sets the typeface in which the text should be displayed on the switch.
|
void |
setSwitchTypeface(Typeface tf,
int style)
Sets the typeface and style in which the text should be displayed on the
switch, and turns on the fake bold and italic bits in the Paint if the
Typeface that you provided does not have all the bits in the
style that you specified.
|
void |
setTextOff(CharSequence textOff)
Sets the text displayed when the button is not in the checked state.
|
void |
setTextOn(CharSequence textOn)
Sets the text displayed when the button is in the checked state.
|
void |
setThumbDrawable(Drawable thumb)
Set the drawable used for the switch "thumb" - the piece that the user
can physically touch and drag along the track.
|
void |
setThumbResource(int resId)
Set the drawable used for the switch "thumb" - the piece that the user
can physically touch and drag along the track.
|
void |
setThumbTextPadding(int pixels)
Set the horizontal padding around the text drawn on the switch itself.
|
void |
setThumbTintList(ColorStateList tint)
Applies a tint to the thumb drawable.
|
void |
setThumbTintMode(PorterDuff.Mode tintMode)
Specifies the blending mode used to apply the tint specified by
setThumbTintList(ColorStateList) } to the thumb drawable. |
void |
setTrackDrawable(Drawable track)
Set the drawable used for the track that the switch slides within.
|
void |
setTrackResource(int resId)
Set the drawable used for the track that the switch slides within.
|
void |
setTrackTintList(ColorStateList tint)
Applies a tint to the track drawable.
|
void |
setTrackTintMode(PorterDuff.Mode tintMode)
Specifies the blending mode used to apply the tint specified by
setTrackTintList(ColorStateList) } to the track drawable. |
void |
toggle()
Change the checked state of the view to the inverse of its current state
|
protected boolean |
verifyDrawable(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.
|
encodeProperties, getAccessibilityClassName, getButtonDrawable, getButtonTintList, getButtonTintMode, getHorizontalOffsetForDrawables, isChecked, onInitializeAccessibilityEventInternal, onInitializeAccessibilityNodeInfoInternal, onResolveDrawables, onRestoreInstanceState, onSaveInstanceState, performClick, setButtonDrawable, setButtonDrawable, setButtonTintList, setButtonTintMode, setOnCheckedChangeListener
addTextChangedListener, append, append, beginBatchEdit, bringPointIntoView, cancelLongPress, clearComposingText, computeHorizontalScrollRange, computeScroll, computeVerticalScrollExtent, computeVerticalScrollRange, debug, deleteText_internal, didTouchFocusSelect, endBatchEdit, extractText, findViewsWithText, getAccessibilitySelectionEnd, getAccessibilitySelectionStart, getAutoLinkMask, getBaseline, getBottomPaddingOffset, getBreakStrategy, getCompoundDrawablePadding, getCompoundDrawables, getCompoundDrawablesRelative, getCompoundDrawableTintList, getCompoundDrawableTintMode, getCompoundPaddingBottom, getCompoundPaddingEnd, getCompoundPaddingStart, getCompoundPaddingTop, getCurrentHintTextColor, getCurrentTextColor, getCustomInsertionActionModeCallback, getCustomSelectionActionModeCallback, getDefaultEditable, getDefaultMovementMethod, getEditableText, getEditorForTesting, getEllipsize, getError, getExtendedPaddingBottom, getExtendedPaddingTop, getFadeHeight, getFadeTop, getFilters, getFocusedRect, getFontFeatureSettings, getFreezesText, getGravity, getHighlightColor, getHint, getHintTextColors, getHorizontallyScrolling, getHyphenationFrequency, getImeActionId, getImeActionLabel, getImeHintLocales, getImeOptions, getIncludeFontPadding, getInputExtras, getInputType, getIterableTextForAccessibility, getIteratorForGranularity, getKeyListener, getLayout, getLeftFadingEdgeStrength, getLeftPaddingOffset, getLetterSpacing, getLineBounds, getLineCount, getLineHeight, getLineSpacingExtra, getLineSpacingMultiplier, getLinksClickable, getLinkTextColors, getMarqueeRepeatLimit, getMaxEms, getMaxHeight, getMaxLines, getMaxWidth, getMinEms, getMinHeight, getMinLines, getMinWidth, getMovementMethod, getOffsetForPosition, getPaint, getPaintFlags, getPrivateImeOptions, getRightFadingEdgeStrength, getRightPaddingOffset, getScaledTextSize, getSelectionEnd, getSelectionStart, getShadowColor, getShadowDx, getShadowDy, getShadowRadius, getShowSoftInputOnFocus, getSpellCheckerLocale, getText, getTextColor, getTextColors, getTextColors, getTextDirectionHeuristic, getTextLocale, getTextLocales, getTextScaleX, getTextServicesLocale, getTextSize, getTopPaddingOffset, getTotalPaddingBottom, getTotalPaddingEnd, getTotalPaddingLeft, getTotalPaddingRight, getTotalPaddingStart, getTotalPaddingTop, getTransformationMethod, getTypeface, getTypefaceStyle, getUndoManager, getUrls, getWordIterator, handleBackInTextActionModeIfNeeded, hasOverlappingRendering, hasSelection, hideErrorIfUnchanged, invalidateDrawable, isAccessibilitySelectionExtendable, isCursorVisible, isInExtractedMode, isInputMethodTarget, isPaddingOffsetRequired, isSuggestionsEnabled, isTextSelectable, length, makeNewLayout, makeSingleLayout, moveCursorToVisibleOffset, onActivityResult, onAttachedToWindow, onBeginBatchEdit, onCheckIsTextEditor, onCommitCompletion, onCommitCorrection, onConfigurationChanged, onCreateContextMenu, onCreateInputConnection, onDetachedFromWindowInternal, onDragEvent, onEditorAction, onEndBatchEdit, onFocusChanged, onGenericMotionEvent, onKeyDown, onKeyMultiple, onKeyPreIme, onKeyShortcut, onKeyUp, onPopulateAccessibilityEventInternal, onPreDraw, onPrivateIMECommand, onProvideStructure, onResolvePointerIcon, onRtlPropertiesChanged, onScreenStateChanged, onScrollChanged, onSelectionChanged, onTextChanged, onTextContextMenuItem, onTrackballEvent, onVisibilityChanged, onWindowFocusChanged, performAccessibilityActionInternal, performLongClick, preloadFontCache, removeTextChangedListener, replaceText_internal, resetErrorChangedFlag, resetResolvedDrawables, sendAccessibilityEventInternal, setAccessibilitySelection, setAllCaps, setAutoLinkMask, setBreakStrategy, setCompoundDrawablePadding, setCompoundDrawables, setCompoundDrawablesRelative, setCompoundDrawablesRelativeWithIntrinsicBounds, setCompoundDrawablesRelativeWithIntrinsicBounds, setCompoundDrawablesWithIntrinsicBounds, setCompoundDrawablesWithIntrinsicBounds, setCompoundDrawableTintList, setCompoundDrawableTintMode, setCursorPosition_internal, setCursorVisible, setCustomInsertionActionModeCallback, setCustomSelectionActionModeCallback, setEditableFactory, setElegantTextHeight, setEllipsize, setEms, setEnabled, setError, setError, setExtractedText, setExtracting, setFilters, setFontFeatureSettings, setFrame, setFreezesText, setGravity, setHeight, setHighlightColor, setHint, setHint, setHintTextColor, setHintTextColor, setHorizontallyScrolling, setHyphenationFrequency, setImeActionLabel, setImeHintLocales, setImeOptions, setIncludeFontPadding, setInputExtras, setInputType, setKeyListener, setLetterSpacing, setLines, setLineSpacing, setLinksClickable, setLinkTextColor, setLinkTextColor, setMarqueeRepeatLimit, setMaxEms, setMaxHeight, setMaxLines, setMaxWidth, setMinEms, setMinHeight, setMinLines, setMinWidth, setMovementMethod, setOnEditorActionListener, setPadding, setPaddingRelative, setPaintFlags, setPrivateImeOptions, setRawInputType, setScroller, setSelectAllOnFocus, setSelected, setShadowLayer, setShowSoftInputOnFocus, setSingleLine, setSingleLine, setSpan_internal, setSpannableFactory, setText, setText, setText, setText, setText, setTextAppearance, setTextAppearance, setTextColor, setTextColor, setTextIsSelectable, setTextKeepState, setTextKeepState, setTextLocale, setTextLocales, setTextScaleX, setTextSize, setTextSize, setTransformationMethod, setTypeface, setTypeface, setUndoManager, setWidth, showContextMenu, showContextMenu, stopTextActionMode, viewClicked
addChildrenForAccessibility, addFocusables, addFocusables, addFrameMetricsListener, addOnAttachStateChangeListener, addOnLayoutChangeListener, addTouchables, animate, announceForAccessibility, applyDrawableToTransparentRegion, awakenScrollBars, awakenScrollBars, awakenScrollBars, bringToFront, buildDrawingCache, buildDrawingCache, buildLayer, callOnClick, cancelDragAndDrop, cancelPendingInputEvents, canHaveDisplayList, canResolveLayoutDirection, canResolveTextAlignment, canResolveTextDirection, canScrollHorizontally, canScrollVertically, captureTransitioningViews, checkInputConnectionProxy, clearAccessibilityFocus, clearAnimation, clearFocus, combineMeasuredStates, computeFitSystemWindows, computeHorizontalScrollExtent, computeHorizontalScrollOffset, computeOpaqueFlags, computeSystemWindowInsets, computeVerticalScrollOffset, createAccessibilityNodeInfo, createAccessibilityNodeInfoInternal, createContextMenu, createSnapshot, damageInParent, debug, debugIndent, destroyDrawingCache, destroyHardwareResources, dispatchActivityResult, dispatchApplyWindowInsets, dispatchConfigurationChanged, dispatchDisplayHint, dispatchDragEvent, dispatchDraw, dispatchDrawableHotspotChanged, dispatchFinishTemporaryDetach, dispatchGenericFocusedEvent, dispatchGenericMotionEvent, dispatchGenericPointerEvent, dispatchGetDisplayList, dispatchHoverEvent, dispatchKeyEvent, dispatchKeyEventPreIme, dispatchKeyShortcutEvent, dispatchNestedFling, dispatchNestedPreFling, dispatchNestedPrePerformAccessibilityAction, dispatchNestedPreScroll, dispatchNestedScroll, dispatchPointerEvent, dispatchPopulateAccessibilityEvent, dispatchPopulateAccessibilityEventInternal, dispatchProvideStructure, dispatchRestoreInstanceState, dispatchSaveInstanceState, dispatchSetActivated, dispatchSetPressed, dispatchSetSelected, dispatchStartTemporaryDetach, dispatchSystemUiVisibilityChanged, dispatchTouchEvent, dispatchTrackballEvent, dispatchUnhandledMove, dispatchVisibilityChanged, dispatchWindowFocusChanged, dispatchWindowSystemUiVisiblityChanged, dispatchWindowVisibilityChanged, encode, findFocus, findNamedViews, findViewByAccessibilityIdTraversal, findViewById, findViewByPredicate, findViewByPredicateInsideOut, findViewByPredicateTraversal, findViewTraversal, findViewWithTag, findViewWithTagTraversal, fitsSystemWindows, fitSystemWindows, focusSearch, forceHasOverlappingRendering, forceLayout, gatherTransparentRegion, generateViewId, getAccessibilityDelegate, getAccessibilityLiveRegion, getAccessibilityNodeProvider, getAccessibilityTraversalAfter, getAccessibilityTraversalBefore, getAccessibilityViewId, getAccessibilityWindowId, getAlpha, getAnimation, getApplicationWindowToken, getBackground, getBackgroundTintList, getBackgroundTintMode, getBottom, getBottomFadingEdgeStrength, getBoundsOnScreen, getBoundsOnScreen, getCameraDistance, getClipBounds, getClipBounds, getClipToOutline, getContentDescription, getContext, getContextMenuInfo, getDefaultSize, getDisplay, getDrawableState, getDrawingCache, getDrawingCache, getDrawingCacheBackgroundColor, getDrawingCacheQuality, getDrawingRect, getDrawingTime, getElevation, getFilterTouchesWhenObscured, getFitsSystemWindows, getFocusables, getForeground, getForegroundGravity, getForegroundTintList, getForegroundTintMode, getGlobalVisibleRect, getGlobalVisibleRect, getHandler, getHardwareRenderer, getHasOverlappingRendering, getHeight, getHitRect, getHorizontalFadingEdgeLength, getHorizontalScrollbarHeight, getHorizontalScrollFactor, getHotspotBounds, getId, getImportantForAccessibility, getInverseMatrix, getKeepScreenOn, getKeyDispatcherState, getLabelFor, getLayerType, getLayoutDirection, getLayoutParams, getLeft, getLocalVisibleRect, getLocationInSurface, getLocationInWindow, getLocationOnScreen, getLocationOnScreen, getMatrix, getMeasuredHeight, getMeasuredHeightAndState, getMeasuredState, getMeasuredWidth, getMeasuredWidthAndState, getMinimumHeight, getMinimumWidth, getNextFocusDownId, getNextFocusForwardId, getNextFocusLeftId, getNextFocusRightId, getNextFocusUpId, getOnFocusChangeListener, getOpticalInsets, getOutlineProvider, getOutsets, getOverlay, getOverScrollMode, getPaddingBottom, getPaddingEnd, getPaddingLeft, getPaddingRight, getPaddingStart, getPaddingTop, getParent, getParentForAccessibility, getPivotX, getPivotY, getPointerIcon, getRawLayoutDirection, getRawTextAlignment, getRawTextDirection, getResources, getRevealOnFocusHint, getRight, getRootView, getRootWindowInsets, getRotation, getRotationX, getRotationY, getScaleX, getScaleY, getScrollBarDefaultDelayBeforeFade, getScrollBarFadeDuration, getScrollBarSize, getScrollBarStyle, getScrollIndicators, getScrollX, getScrollY, getSolidColor, getStateListAnimator, getSuggestedMinimumHeight, getSuggestedMinimumWidth, getSystemUiVisibility, getTag, getTag, getTextAlignment, getTextDirection, getTop, getTopFadingEdgeStrength, getTouchables, getTouchDelegate, getTransitionAlpha, getTransitionName, getTranslationX, getTranslationY, getTranslationZ, getVerticalFadingEdgeLength, getVerticalScrollbarPosition, getVerticalScrollbarWidth, getVerticalScrollFactor, getViewRootImpl, getViewTreeObserver, getVisibility, getWidth, getWindowAttachCount, getWindowDisplayFrame, getWindowId, getWindowSystemUiVisibility, getWindowToken, getWindowVisibility, getWindowVisibleDisplayFrame, getX, getY, getZ, handleScrollBarDragging, hasFocus, hasFocusable, hasHoveredChild, hasNestedScrollingParent, hasOnClickListeners, hasOpaqueScrollbars, hasShadow, hasTransientState, hasWindowFocus, includeForAccessibility, inflate, initializeFadingEdge, initializeFadingEdgeInternal, initializeScrollbars, initializeScrollbarsInternal, internalSetPadding, invalidate, invalidate, invalidate, invalidateOutline, invalidateParentCaches, invalidateParentIfNeeded, invalidateParentIfNeededAndWasQuickRejected, isAccessibilityFocused, isActionableForAccessibility, isActivated, isAssistBlocked, isAttachedToWindow, isClickable, isContextClickable, isDirty, isDrawingCacheEnabled, isDuplicateParentStateEnabled, isEnabled, isFocusable, isFocusableInTouchMode, isFocused, isForegroundInsidePadding, isHapticFeedbackEnabled, isHardwareAccelerated, isHorizontalFadingEdgeEnabled, isHorizontalScrollBarEnabled, isHovered, isImportantForAccessibility, isInEditMode, isInLayout, isInScrollingContainer, isInTouchMode, isLaidOut, isLayoutDirectionInherited, isLayoutDirectionResolved, isLayoutModeOptical, isLayoutRequested, isLayoutRtl, isLongClickable, isNestedScrollingEnabled, isOpaque, isPaddingRelative, isPressed, isRootNamespace, isSaveEnabled, isSaveFromParentEnabled, isScrollbarFadingEnabled, isScrollContainer, isSelected, isShown, isSoundEffectsEnabled, isTemporarilyDetached, isTextAlignmentInherited, isTextAlignmentResolved, isTextDirectionInherited, isTextDirectionResolved, isVerticalFadingEdgeEnabled, isVerticalScrollBarEnabled, isVerticalScrollBarHidden, isVisibleToUser, isVisibleToUser, layout, makeOptionalFitsSystemWindows, measure, mergeDrawableStates, notifySubtreeAccessibilityStateChangedIfNeeded, notifyViewAccessibilityStateChangedIfNeeded, offsetLeftAndRight, offsetTopAndBottom, onAnimationEnd, onAnimationStart, onApplyWindowInsets, onCancelPendingInputEvents, onCloseSystemDialogs, onDetachedFromWindow, onDisplayHint, onDrawForeground, onDrawHorizontalScrollBar, onDrawScrollBars, onDrawVerticalScrollBar, onFilterTouchEventForSecurity, onFinishInflate, onFinishTemporaryDetach, onFocusLost, onHoverChanged, onHoverEvent, onKeyLongPress, onOverScrolled, onProvideVirtualStructure, onRenderNodeDetached, onSetAlpha, onSizeChanged, onStartTemporaryDetach, onVisibilityAggregated, onWindowSystemUiVisibilityChanged, onWindowVisibilityChanged, outputDirtyFlags, overScrollBy, performAccessibilityAction, performButtonActionOnTouchDown, performContextClick, performContextClick, performHapticFeedback, performHapticFeedback, performLongClick, playSoundEffect, pointInView, post, postDelayed, postInvalidate, postInvalidate, postInvalidateDelayed, postInvalidateDelayed, postInvalidateOnAnimation, postInvalidateOnAnimation, postOnAnimation, postOnAnimationDelayed, recomputePadding, refreshDrawableState, removeCallbacks, removeFrameMetricsListener, removeOnAttachStateChangeListener, removeOnLayoutChangeListener, requestAccessibilityFocus, requestApplyInsets, requestFitSystemWindows, requestFocus, requestFocus, requestFocus, requestFocusFromTouch, requestKeyboardShortcuts, requestLayout, requestRectangleOnScreen, requestRectangleOnScreen, requestUnbufferedDispatch, resetPaddingToInitialValues, resetResolvedLayoutDirection, resetResolvedPadding, resetResolvedTextAlignment, resetResolvedTextDirection, resetRtlProperties, resolveDrawables, resolveLayoutDirection, resolveLayoutParams, resolvePadding, resolveRtlPropertiesIfNeeded, resolveSize, resolveSizeAndState, resolveTextAlignment, resolveTextDirection, restoreHierarchyState, saveHierarchyState, scheduleDrawable, scrollBy, scrollTo, sendAccessibilityEvent, sendAccessibilityEventUnchecked, sendAccessibilityEventUncheckedInternal, setAccessibilityDelegate, setAccessibilityLiveRegion, setAccessibilityTraversalAfter, setAccessibilityTraversalBefore, setActivated, setAlpha, setAnimation, setAnimationMatrix, setAssistBlocked, setBackground, setBackgroundColor, setBackgroundDrawable, setBackgroundResource, setBackgroundTintList, setBackgroundTintMode, setBottom, setCameraDistance, setClickable, setClipBounds, setClipToOutline, setContentDescription, setContextClickable, setDisabledSystemUiVisibility, setDrawingCacheBackgroundColor, setDrawingCacheEnabled, setDrawingCacheQuality, setDuplicateParentStateEnabled, setElevation, setFadingEdgeLength, setFilterTouchesWhenObscured, setFitsSystemWindows, setFocusable, setFocusableInTouchMode, setForeground, setForegroundGravity, setForegroundTintList, setForegroundTintMode, setHapticFeedbackEnabled, setHasTransientState, setHorizontalFadingEdgeEnabled, setHorizontalScrollBarEnabled, setHovered, setId, setImportantForAccessibility, setIsRootNamespace, setKeepScreenOn, setLabelFor, setLayerPaint, setLayerType, setLayoutDirection, setLayoutParams, setLeft, setLeftTopRightBottom, setLongClickable, setMeasuredDimension, setMinimumHeight, setMinimumWidth, setNestedScrollingEnabled, setNextFocusDownId, setNextFocusForwardId, setNextFocusLeftId, setNextFocusRightId, setNextFocusUpId, setOnApplyWindowInsetsListener, setOnClickListener, setOnContextClickListener, setOnCreateContextMenuListener, setOnDragListener, setOnFocusChangeListener, setOnGenericMotionListener, setOnHoverListener, setOnKeyListener, setOnLongClickListener, setOnScrollChangeListener, setOnSystemUiVisibilityChangeListener, setOnTouchListener, setOpticalInsets, setOutlineProvider, setOverScrollMode, setPivotX, setPivotY, setPointerIcon, setPressed, setRevealClip, setRevealOnFocusHint, setRight, setRotation, setRotationX, setRotationY, setSaveEnabled, setSaveFromParentEnabled, setScaleX, setScaleY, setScrollBarDefaultDelayBeforeFade, setScrollBarFadeDuration, setScrollbarFadingEnabled, setScrollBarSize, setScrollBarStyle, setScrollContainer, setScrollIndicators, setScrollIndicators, setScrollX, setScrollY, setSoundEffectsEnabled, setStateListAnimator, setSystemUiVisibility, setTag, setTag, setTagInternal, setTextAlignment, setTextDirection, setTop, setTouchDelegate, setTransitionAlpha, setTransitionName, setTransitionVisibility, setTranslationX, setTranslationY, setTranslationZ, setVerticalFadingEdgeEnabled, setVerticalScrollBarEnabled, setVerticalScrollbarPosition, setVisibility, setWillNotCacheDrawing, setWillNotDraw, setX, setY, setZ, startActionMode, startActionMode, startActivityForResult, startAnimation, startDrag, startDragAndDrop, startMovingTask, startNestedScroll, stopNestedScroll, toGlobalMotionEvent, toLocalMotionEvent, toString, transformFromViewToWindowSpace, transformMatrixToGlobal, transformMatrixToLocal, unscheduleDrawable, unscheduleDrawable, updateDisplayListIfDirty, updateDragShadow, willNotCacheDrawing, willNotDraw
public SwitchCompat(Context context)
context
- The Context that will determine this widget's theming.public SwitchCompat(Context context, AttributeSet attrs)
context
- The Context that will determine this widget's theming.attrs
- Specification of attributes that should deviate from default styling.public SwitchCompat(Context context, AttributeSet attrs, int defStyleAttr)
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 0 to not look for defaults.public void setSwitchTextAppearance(Context context, int resid)
public void setSwitchTypeface(Typeface tf, int style)
public void setSwitchTypeface(Typeface tf)
setSwitchTypeface(Typeface, int)
to get the appearance
that you actually want.public void setSwitchPadding(int pixels)
pixels
- Amount of padding in pixelspublic int getSwitchPadding()
public void setSwitchMinWidth(int pixels)
pixels
- Minimum width of the switch in pixelspublic int getSwitchMinWidth()
public void setThumbTextPadding(int pixels)
pixels
- Horizontal padding for switch thumb text in pixelspublic int getThumbTextPadding()
public void setTrackDrawable(Drawable track)
track
- Track drawablepublic void setTrackResource(int resId)
resId
- Resource ID of a track drawablepublic Drawable getTrackDrawable()
public void setTrackTintList(@Nullable ColorStateList tint)
PorterDuff.Mode#SRC_IN
by default.
Subsequent calls to setTrackDrawable(Drawable)
will
automatically mutate the drawable and apply the specified tint and tint
mode using DrawableCompat.setTintList(Drawable, ColorStateList)
.
tint
- the tint to apply, may be null
to clear tintgetTrackTintList()
@Nullable public ColorStateList getTrackTintList()
setTrackTintList(ColorStateList)
public void setTrackTintMode(@Nullable PorterDuff.Mode tintMode)
setTrackTintList(ColorStateList)
} to the track drawable.
The default mode is PorterDuff.Mode#SRC_IN
.tintMode
- the blending mode used to apply the tint, may be
null
to clear tintgetTrackTintMode()
@Nullable public PorterDuff.Mode getTrackTintMode()
setTrackTintMode(PorterDuff.Mode)
public void setThumbDrawable(Drawable thumb)
thumb
- Thumb drawablepublic void setThumbResource(int resId)
resId
- Resource ID of a thumb drawablepublic Drawable getThumbDrawable()
public void setThumbTintList(@Nullable ColorStateList tint)
PorterDuff.Mode#SRC_IN
by default.
Subsequent calls to setThumbDrawable(Drawable)
will
automatically mutate the drawable and apply the specified tint and tint
mode using DrawableCompat.setTintList(Drawable, ColorStateList)
.
tint
- the tint to apply, may be null
to clear tintgetThumbTintList()
,
Drawable.setTintList(ColorStateList)
@Nullable public ColorStateList getThumbTintList()
setThumbTintList(ColorStateList)
public void setThumbTintMode(@Nullable PorterDuff.Mode tintMode)
setThumbTintList(ColorStateList)
} to the thumb drawable.
The default mode is PorterDuff.Mode#SRC_IN
.tintMode
- the blending mode used to apply the tint, may be
null
to clear tintgetThumbTintMode()
,
Drawable.setTintMode(PorterDuff.Mode)
@Nullable public PorterDuff.Mode getThumbTintMode()
setThumbTintMode(PorterDuff.Mode)
public void setSplitTrack(boolean splitTrack)
splitTrack
- Whether the track should be split by the thumbpublic boolean getSplitTrack()
public CharSequence getTextOn()
public void setTextOn(CharSequence textOn)
public CharSequence getTextOff()
public void setTextOff(CharSequence textOff)
public void setShowText(boolean showText)
showText
- true
to display on/off textpublic boolean getShowText()
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
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 the superclass'
View.onMeasure(int, int)
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 View.onMeasure(int, int)
to provide better measurements of
their content.
If this method is overridden, it is the subclass's responsibility to make
sure the measured height and width are at least the view's minimum height
and width (View.getSuggestedMinimumHeight()
and
View.getSuggestedMinimumWidth()
).
onMeasure
in class TextView
widthMeasureSpec
- horizontal space requirements as imposed by the parent.
The requirements are encoded with
View.MeasureSpec
.heightMeasureSpec
- vertical space requirements as imposed by the parent.
The requirements are encoded with
View.MeasureSpec
.View.getMeasuredWidth()
,
View.getMeasuredHeight()
,
View.setMeasuredDimension(int, int)
,
View.getSuggestedMinimumHeight()
,
View.getSuggestedMinimumWidth()
,
View.MeasureSpec.getMode(int)
,
View.MeasureSpec.getSize(int)
public void onPopulateAccessibilityEvent(AccessibilityEvent event)
View
View.dispatchPopulateAccessibilityEvent(AccessibilityEvent)
giving a chance to this View to populate the accessibility event with its
text content. While this method is free to modify event
attributes other than text content, doing so should normally be performed in
View.onInitializeAccessibilityEvent(AccessibilityEvent)
.
Example: Adding formatted date string to an accessibility event in addition to the text added by the super implementation:
public void onPopulateAccessibilityEvent(AccessibilityEvent event) { super.onPopulateAccessibilityEvent(event); final int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY; String selectedDateUtterance = DateUtils.formatDateTime(mContext, mCurrentDate.getTimeInMillis(), flags); event.getText().add(selectedDateUtterance); }
If an View.AccessibilityDelegate
has been specified via calling
View.setAccessibilityDelegate(AccessibilityDelegate)
its
View.AccessibilityDelegate.onPopulateAccessibilityEvent(View, AccessibilityEvent)
is responsible for handling this call.
Note: Always call the super implementation before adding information to the event, in case the default implementation has basic information to add.
onPopulateAccessibilityEvent
in class View
event
- The accessibility event which to populate.View.sendAccessibilityEvent(int)
,
View.dispatchPopulateAccessibilityEvent(AccessibilityEvent)
public boolean onTouchEvent(MotionEvent ev)
View
If this method is used to detect click actions, it is recommended that
the actions be performed by implementing and calling
View.performClick()
. This will ensure consistent system behavior,
including:
ACTION_CLICK
when
accessibility features are enabled
onTouchEvent
in class TextView
ev
- The motion event.public void toggle()
Checkable
toggle
in interface Checkable
toggle
in class CompoundButton
public void setChecked(boolean checked)
CompoundButton
Changes the checked state of this button.
setChecked
in interface Checkable
setChecked
in class CompoundButton
checked
- true to check the button, false to uncheck itprotected void onLayout(boolean changed, int left, int top, int right, int bottom)
View
public void draw(Canvas c)
View
View.onDraw(android.graphics.Canvas)
instead of overriding this method.
If you do need to override this method, call the superclass version.protected void onDraw(Canvas canvas)
View
onDraw
in class CompoundButton
canvas
- the canvas on which the background will be drawnpublic int getCompoundPaddingLeft()
TextView
getCompoundPaddingLeft
in class CompoundButton
public int getCompoundPaddingRight()
TextView
getCompoundPaddingRight
in class CompoundButton
protected int[] onCreateDrawableState(int extraSpace)
View
Drawable
state 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 use View.getDrawableState()
.onCreateDrawableState
in class CompoundButton
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.Drawable
state of
the view.View.mergeDrawableStates(int[], int[])
protected void drawableStateChanged()
View
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.
drawableStateChanged
in class CompoundButton
Drawable.setState(int[])
public void drawableHotspotChanged(float x, float y)
View
Dispatching to child views is handled by
View.dispatchDrawableHotspotChanged(float, float)
.
Be sure to call through to the superclass when overriding this function.
drawableHotspotChanged
in class CompoundButton
x
- hotspot x coordinatey
- hotspot y coordinateprotected boolean verifyDrawable(Drawable who)
View
Be sure to call through to the super class when overriding this function.
verifyDrawable
in class CompoundButton
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.View.unscheduleDrawable(android.graphics.drawable.Drawable)
,
View.drawableStateChanged()
public void jumpDrawablesToCurrentState()
View
Drawable.jumpToCurrentState()
on all Drawable objects associated with this view.
Also calls StateListAnimator.jumpToCurrentState()
if there is a StateListAnimator
attached to this view.
jumpDrawablesToCurrentState
in class CompoundButton
public void onInitializeAccessibilityEvent(AccessibilityEvent event)
View
AccessibilityEvent
with information about
this View which is the event source. In other words, the source of
an accessibility event is the view whose state change triggered firing
the event.
Example: Setting the password property of an event in addition to properties set by the super implementation:
public void onInitializeAccessibilityEvent(AccessibilityEvent event) { super.onInitializeAccessibilityEvent(event); event.setPassword(true); }
If an View.AccessibilityDelegate
has been specified via calling
View.setAccessibilityDelegate(AccessibilityDelegate)
its
View.AccessibilityDelegate.onInitializeAccessibilityEvent(View, AccessibilityEvent)
is responsible for handling this call.
Note: Always call the super implementation before adding information to the event, in case the default implementation has basic information to add.
onInitializeAccessibilityEvent
in class View
event
- The event to initialize.View.sendAccessibilityEvent(int)
,
View.dispatchPopulateAccessibilityEvent(AccessibilityEvent)
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info)
View
AccessibilityNodeInfo
with information about this view.
The base implementation sets:
AccessibilityNodeInfo.setParent(View)
,AccessibilityNodeInfo.setBoundsInParent(Rect)
,AccessibilityNodeInfo.setBoundsInScreen(Rect)
,AccessibilityNodeInfo.setPackageName(CharSequence)
,AccessibilityNodeInfo.setClassName(CharSequence)
,AccessibilityNodeInfo.setContentDescription(CharSequence)
,AccessibilityNodeInfo.setEnabled(boolean)
,AccessibilityNodeInfo.setClickable(boolean)
,AccessibilityNodeInfo.setFocusable(boolean)
,AccessibilityNodeInfo.setFocused(boolean)
,AccessibilityNodeInfo.setLongClickable(boolean)
,AccessibilityNodeInfo.setSelected(boolean)
,AccessibilityNodeInfo.setContextClickable(boolean)
Subclasses should override this method, call the super implementation, and set additional attributes.
If an View.AccessibilityDelegate
has been specified via calling
View.setAccessibilityDelegate(AccessibilityDelegate)
its
View.AccessibilityDelegate.onInitializeAccessibilityNodeInfo(View, AccessibilityNodeInfo)
is responsible for handling this call.
onInitializeAccessibilityNodeInfo
in class View
info
- The instance to initialize.