Loading api/current.txt +10 −0 Original line number Original line Diff line number Diff line Loading @@ -1316,6 +1316,8 @@ package android { field public static final int topRightRadius = 16843178; // 0x10101aa field public static final int topRightRadius = 16843178; // 0x10101aa field public static final int touchscreenBlocksFocus = 16843919; // 0x101048f field public static final int touchscreenBlocksFocus = 16843919; // 0x101048f field public static final int track = 16843631; // 0x101036f field public static final int track = 16843631; // 0x101036f field public static final int trackTint = 16843993; // 0x10104d9 field public static final int trackTintMode = 16843994; // 0x10104da field public static final int transcriptMode = 16843008; // 0x1010100 field public static final int transcriptMode = 16843008; // 0x1010100 field public static final int transformPivotX = 16843552; // 0x1010320 field public static final int transformPivotX = 16843552; // 0x1010320 field public static final int transformPivotY = 16843553; // 0x1010321 field public static final int transformPivotY = 16843553; // 0x1010321 Loading Loading @@ -39056,7 +39058,11 @@ package android.widget { method public java.lang.CharSequence getTextOn(); method public java.lang.CharSequence getTextOn(); method public android.graphics.drawable.Drawable getThumbDrawable(); method public android.graphics.drawable.Drawable getThumbDrawable(); method public int getThumbTextPadding(); method public int getThumbTextPadding(); method public android.content.res.ColorStateList getThumbTintList(); method public android.graphics.PorterDuff.Mode getThumbTintMode(); method public android.graphics.drawable.Drawable getTrackDrawable(); method public android.graphics.drawable.Drawable getTrackDrawable(); method public android.content.res.ColorStateList getTrackTintList(); method public android.graphics.PorterDuff.Mode getTrackTintMode(); method public void onMeasure(int, int); method public void onMeasure(int, int); method public void setShowText(boolean); method public void setShowText(boolean); method public void setSplitTrack(boolean); method public void setSplitTrack(boolean); Loading @@ -39070,8 +39076,12 @@ package android.widget { method public void setThumbDrawable(android.graphics.drawable.Drawable); method public void setThumbDrawable(android.graphics.drawable.Drawable); method public void setThumbResource(int); method public void setThumbResource(int); method public void setThumbTextPadding(int); method public void setThumbTextPadding(int); method public void setThumbTintList(android.content.res.ColorStateList); method public void setThumbTintMode(android.graphics.PorterDuff.Mode); method public void setTrackDrawable(android.graphics.drawable.Drawable); method public void setTrackDrawable(android.graphics.drawable.Drawable); method public void setTrackResource(int); method public void setTrackResource(int); method public void setTrackTintList(android.content.res.ColorStateList); method public void setTrackTintMode(android.graphics.PorterDuff.Mode); } } public class TabHost extends android.widget.FrameLayout implements android.view.ViewTreeObserver.OnTouchModeChangeListener { public class TabHost extends android.widget.FrameLayout implements android.view.ViewTreeObserver.OnTouchModeChangeListener { api/system-current.txt +10 −0 Original line number Original line Diff line number Diff line Loading @@ -1392,6 +1392,8 @@ package android { field public static final int topRightRadius = 16843178; // 0x10101aa field public static final int topRightRadius = 16843178; // 0x10101aa field public static final int touchscreenBlocksFocus = 16843919; // 0x101048f field public static final int touchscreenBlocksFocus = 16843919; // 0x101048f field public static final int track = 16843631; // 0x101036f field public static final int track = 16843631; // 0x101036f field public static final int trackTint = 16843993; // 0x10104d9 field public static final int trackTintMode = 16843994; // 0x10104da field public static final int transcriptMode = 16843008; // 0x1010100 field public static final int transcriptMode = 16843008; // 0x1010100 field public static final int transformPivotX = 16843552; // 0x1010320 field public static final int transformPivotX = 16843552; // 0x1010320 field public static final int transformPivotY = 16843553; // 0x1010321 field public static final int transformPivotY = 16843553; // 0x1010321 Loading Loading @@ -41551,7 +41553,11 @@ package android.widget { method public java.lang.CharSequence getTextOn(); method public java.lang.CharSequence getTextOn(); method public android.graphics.drawable.Drawable getThumbDrawable(); method public android.graphics.drawable.Drawable getThumbDrawable(); method public int getThumbTextPadding(); method public int getThumbTextPadding(); method public android.content.res.ColorStateList getThumbTintList(); method public android.graphics.PorterDuff.Mode getThumbTintMode(); method public android.graphics.drawable.Drawable getTrackDrawable(); method public android.graphics.drawable.Drawable getTrackDrawable(); method public android.content.res.ColorStateList getTrackTintList(); method public android.graphics.PorterDuff.Mode getTrackTintMode(); method public void onMeasure(int, int); method public void onMeasure(int, int); method public void setShowText(boolean); method public void setShowText(boolean); method public void setSplitTrack(boolean); method public void setSplitTrack(boolean); Loading @@ -41565,8 +41571,12 @@ package android.widget { method public void setThumbDrawable(android.graphics.drawable.Drawable); method public void setThumbDrawable(android.graphics.drawable.Drawable); method public void setThumbResource(int); method public void setThumbResource(int); method public void setThumbTextPadding(int); method public void setThumbTextPadding(int); method public void setThumbTintList(android.content.res.ColorStateList); method public void setThumbTintMode(android.graphics.PorterDuff.Mode); method public void setTrackDrawable(android.graphics.drawable.Drawable); method public void setTrackDrawable(android.graphics.drawable.Drawable); method public void setTrackResource(int); method public void setTrackResource(int); method public void setTrackTintList(android.content.res.ColorStateList); method public void setTrackTintMode(android.graphics.PorterDuff.Mode); } } public class TabHost extends android.widget.FrameLayout implements android.view.ViewTreeObserver.OnTouchModeChangeListener { public class TabHost extends android.widget.FrameLayout implements android.view.ViewTreeObserver.OnTouchModeChangeListener { core/java/android/widget/Switch.java +172 −0 Original line number Original line Diff line number Diff line Loading @@ -17,6 +17,7 @@ package android.widget; package android.widget; import android.animation.ObjectAnimator; import android.animation.ObjectAnimator; import android.annotation.Nullable; import android.content.Context; import android.content.Context; import android.content.res.ColorStateList; import android.content.res.ColorStateList; import android.content.res.Resources; import android.content.res.Resources; Loading @@ -24,6 +25,7 @@ import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.Canvas; import android.graphics.Insets; import android.graphics.Insets; import android.graphics.Paint; import android.graphics.Paint; import android.graphics.PorterDuff; import android.graphics.Rect; import android.graphics.Rect; import android.graphics.Typeface; import android.graphics.Typeface; import android.graphics.Region.Op; import android.graphics.Region.Op; Loading Loading @@ -84,7 +86,17 @@ public class Switch extends CompoundButton { private static final int MONOSPACE = 3; private static final int MONOSPACE = 3; private Drawable mThumbDrawable; private Drawable mThumbDrawable; private ColorStateList mThumbTintList = null; private PorterDuff.Mode mThumbTintMode = null; private boolean mHasThumbTint = false; private boolean mHasThumbTintMode = false; private Drawable mTrackDrawable; private Drawable mTrackDrawable; private ColorStateList mTrackTintList = null; private PorterDuff.Mode mTrackTintMode = null; private boolean mHasTrackTint = false; private boolean mHasTrackTintMode = false; private int mThumbTextPadding; private int mThumbTextPadding; private int mSwitchMinWidth; private int mSwitchMinWidth; private int mSwitchPadding; private int mSwitchPadding; Loading Loading @@ -472,6 +484,86 @@ public class Switch extends CompoundButton { return mTrackDrawable; return mTrackDrawable; } } /** * Applies a tint to the track drawable. Does not modify the current * tint mode, which is {@link PorterDuff.Mode#SRC_IN} by default. * <p> * Subsequent calls to {@link #setTrackDrawable(Drawable)} will * automatically mutate the drawable and apply the specified tint and tint * mode using {@link Drawable#setTintList(ColorStateList)}. * * @param tint the tint to apply, may be {@code null} to clear tint * * @attr ref android.R.styleable#Switch_trackTint * @see #getTrackTintList() * @see Drawable#setTintList(ColorStateList) */ public void setTrackTintList(@Nullable ColorStateList tint) { mTrackTintList = tint; mHasTrackTint = true; applyTrackTint(); } /** * @return the tint applied to the track drawable * @attr ref android.R.styleable#Switch_trackTint * @see #setTrackTintList(ColorStateList) */ @Nullable public ColorStateList getTrackTintList() { return mTrackTintList; } /** * Specifies the blending mode used to apply the tint specified by * {@link #setTrackTintList(ColorStateList)}} to the track drawable. * The default mode is {@link PorterDuff.Mode#SRC_IN}. * * @param tintMode the blending mode used to apply the tint, may be * {@code null} to clear tint * @attr ref android.R.styleable#Switch_trackTintMode * @see #getTrackTintMode() * @see Drawable#setTintMode(PorterDuff.Mode) */ public void setTrackTintMode(@Nullable PorterDuff.Mode tintMode) { mTrackTintMode = tintMode; mHasTrackTintMode = true; applyTrackTint(); } /** * @return the blending mode used to apply the tint to the track * drawable * @attr ref android.R.styleable#Switch_trackTintMode * @see #setTrackTintMode(PorterDuff.Mode) */ @Nullable public PorterDuff.Mode getTrackTintMode() { return mTrackTintMode; } private void applyTrackTint() { if (mTrackDrawable != null && (mHasTrackTint || mHasTrackTintMode)) { mTrackDrawable = mTrackDrawable.mutate(); if (mHasTrackTint) { mTrackDrawable.setTintList(mTrackTintList); } if (mHasTrackTintMode) { mTrackDrawable.setTintMode(mTrackTintMode); } // The drawable (or one of its children) may not have been // stateful before applying the tint, so let's try again. if (mTrackDrawable.isStateful()) { mTrackDrawable.setState(getDrawableState()); } } } /** /** * Set the drawable used for the switch "thumb" - the piece that the user * Set the drawable used for the switch "thumb" - the piece that the user * can physically touch and drag along the track. * can physically touch and drag along the track. Loading Loading @@ -515,6 +607,86 @@ public class Switch extends CompoundButton { return mThumbDrawable; return mThumbDrawable; } } /** * Applies a tint to the thumb drawable. Does not modify the current * tint mode, which is {@link PorterDuff.Mode#SRC_IN} by default. * <p> * Subsequent calls to {@link #setThumbDrawable(Drawable)} will * automatically mutate the drawable and apply the specified tint and tint * mode using {@link Drawable#setTintList(ColorStateList)}. * * @param tint the tint to apply, may be {@code null} to clear tint * * @attr ref android.R.styleable#Switch_thumbTint * @see #getThumbTintList() * @see Drawable#setTintList(ColorStateList) */ public void setThumbTintList(@Nullable ColorStateList tint) { mThumbTintList = tint; mHasThumbTint = true; applyThumbTint(); } /** * @return the tint applied to the thumb drawable * @attr ref android.R.styleable#Switch_thumbTint * @see #setThumbTintList(ColorStateList) */ @Nullable public ColorStateList getThumbTintList() { return mThumbTintList; } /** * Specifies the blending mode used to apply the tint specified by * {@link #setThumbTintList(ColorStateList)}} to the thumb drawable. * The default mode is {@link PorterDuff.Mode#SRC_IN}. * * @param tintMode the blending mode used to apply the tint, may be * {@code null} to clear tint * @attr ref android.R.styleable#Switch_thumbTintMode * @see #getThumbTintMode() * @see Drawable#setTintMode(PorterDuff.Mode) */ public void setThumbTintMode(@Nullable PorterDuff.Mode tintMode) { mThumbTintMode = tintMode; mHasThumbTintMode = true; applyThumbTint(); } /** * @return the blending mode used to apply the tint to the thumb * drawable * @attr ref android.R.styleable#Switch_thumbTintMode * @see #setThumbTintMode(PorterDuff.Mode) */ @Nullable public PorterDuff.Mode getThumbTintMode() { return mThumbTintMode; } private void applyThumbTint() { if (mThumbDrawable != null && (mHasThumbTint || mHasThumbTintMode)) { mThumbDrawable = mThumbDrawable.mutate(); if (mHasThumbTint) { mThumbDrawable.setTintList(mThumbTintList); } if (mHasThumbTintMode) { mThumbDrawable.setTintMode(mThumbTintMode); } // The drawable (or one of its children) may not have been // stateful before applying the tint, so let's try again. if (mThumbDrawable.isStateful()) { mThumbDrawable.setState(getDrawableState()); } } } /** /** * Specifies whether the track should be split by the thumb. When true, * 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, * the thumb's optical bounds will be clipped out of the track drawable, Loading core/res/res/values/attrs.xml +26 −0 Original line number Original line Diff line number Diff line Loading @@ -7261,8 +7261,34 @@ <declare-styleable name="Switch"> <declare-styleable name="Switch"> <!-- Drawable to use as the "thumb" that switches back and forth. --> <!-- Drawable to use as the "thumb" that switches back and forth. --> <attr name="thumb" /> <attr name="thumb" /> <!-- Tint to apply to the thumb. --> <attr name="thumbTint" /> <!-- Blending mode used to apply the thumb tint. --> <attr name="thumbTintMode" /> <!-- Drawable to use as the "track" that the switch thumb slides within. --> <!-- Drawable to use as the "track" that the switch thumb slides within. --> <attr name="track" format="reference" /> <attr name="track" format="reference" /> <!-- Tint to apply to the track. --> <attr name="trackTint" format="color" /> <!-- Blending mode used to apply the track tint. --> <attr name="trackTintMode"> <!-- The tint is drawn on top of the drawable. [Sa + (1 - Sa)*Da, Rc = Sc + (1 - Sa)*Dc] --> <enum name="src_over" value="3" /> <!-- The tint is masked by the alpha channel of the drawable. The drawable’s color channels are thrown out. [Sa * Da, Sc * Da] --> <enum name="src_in" value="5" /> <!-- The tint is drawn above the drawable, but with the drawable’s alpha channel masking the result. [Da, Sc * Da + (1 - Sa) * Dc] --> <enum name="src_atop" value="9" /> <!-- Multiplies the color and alpha channels of the drawable with those of the tint. [Sa * Da, Sc * Dc] --> <enum name="multiply" value="14" /> <!-- [Sa + Da - Sa * Da, Sc + Dc - Sc * Dc] --> <enum name="screen" value="15" /> <!-- Combines the tint and drawable color and alpha channels, clamping the result to valid color values. Saturate(S + D) --> <enum name="add" value="16" /> </attr> <!-- Text to use when the switch is in the checked/"on" state. --> <!-- Text to use when the switch is in the checked/"on" state. --> <attr name="textOn" /> <attr name="textOn" /> <!-- Text to use when the switch is in the unchecked/"off" state. --> <!-- Text to use when the switch is in the unchecked/"off" state. --> Loading core/res/res/values/public.xml +3 −0 Original line number Original line Diff line number Diff line Loading @@ -2608,6 +2608,9 @@ =============================================================== --> =============================================================== --> <eat-comment /> <eat-comment /> <public type="attr" name="trackTint" /> <public type="attr" name="trackTintMode" /> <public type="style" name="Widget.Material.Button.Colored" /> <public type="style" name="Widget.Material.Button.Colored" /> </resources> </resources> Loading
api/current.txt +10 −0 Original line number Original line Diff line number Diff line Loading @@ -1316,6 +1316,8 @@ package android { field public static final int topRightRadius = 16843178; // 0x10101aa field public static final int topRightRadius = 16843178; // 0x10101aa field public static final int touchscreenBlocksFocus = 16843919; // 0x101048f field public static final int touchscreenBlocksFocus = 16843919; // 0x101048f field public static final int track = 16843631; // 0x101036f field public static final int track = 16843631; // 0x101036f field public static final int trackTint = 16843993; // 0x10104d9 field public static final int trackTintMode = 16843994; // 0x10104da field public static final int transcriptMode = 16843008; // 0x1010100 field public static final int transcriptMode = 16843008; // 0x1010100 field public static final int transformPivotX = 16843552; // 0x1010320 field public static final int transformPivotX = 16843552; // 0x1010320 field public static final int transformPivotY = 16843553; // 0x1010321 field public static final int transformPivotY = 16843553; // 0x1010321 Loading Loading @@ -39056,7 +39058,11 @@ package android.widget { method public java.lang.CharSequence getTextOn(); method public java.lang.CharSequence getTextOn(); method public android.graphics.drawable.Drawable getThumbDrawable(); method public android.graphics.drawable.Drawable getThumbDrawable(); method public int getThumbTextPadding(); method public int getThumbTextPadding(); method public android.content.res.ColorStateList getThumbTintList(); method public android.graphics.PorterDuff.Mode getThumbTintMode(); method public android.graphics.drawable.Drawable getTrackDrawable(); method public android.graphics.drawable.Drawable getTrackDrawable(); method public android.content.res.ColorStateList getTrackTintList(); method public android.graphics.PorterDuff.Mode getTrackTintMode(); method public void onMeasure(int, int); method public void onMeasure(int, int); method public void setShowText(boolean); method public void setShowText(boolean); method public void setSplitTrack(boolean); method public void setSplitTrack(boolean); Loading @@ -39070,8 +39076,12 @@ package android.widget { method public void setThumbDrawable(android.graphics.drawable.Drawable); method public void setThumbDrawable(android.graphics.drawable.Drawable); method public void setThumbResource(int); method public void setThumbResource(int); method public void setThumbTextPadding(int); method public void setThumbTextPadding(int); method public void setThumbTintList(android.content.res.ColorStateList); method public void setThumbTintMode(android.graphics.PorterDuff.Mode); method public void setTrackDrawable(android.graphics.drawable.Drawable); method public void setTrackDrawable(android.graphics.drawable.Drawable); method public void setTrackResource(int); method public void setTrackResource(int); method public void setTrackTintList(android.content.res.ColorStateList); method public void setTrackTintMode(android.graphics.PorterDuff.Mode); } } public class TabHost extends android.widget.FrameLayout implements android.view.ViewTreeObserver.OnTouchModeChangeListener { public class TabHost extends android.widget.FrameLayout implements android.view.ViewTreeObserver.OnTouchModeChangeListener {
api/system-current.txt +10 −0 Original line number Original line Diff line number Diff line Loading @@ -1392,6 +1392,8 @@ package android { field public static final int topRightRadius = 16843178; // 0x10101aa field public static final int topRightRadius = 16843178; // 0x10101aa field public static final int touchscreenBlocksFocus = 16843919; // 0x101048f field public static final int touchscreenBlocksFocus = 16843919; // 0x101048f field public static final int track = 16843631; // 0x101036f field public static final int track = 16843631; // 0x101036f field public static final int trackTint = 16843993; // 0x10104d9 field public static final int trackTintMode = 16843994; // 0x10104da field public static final int transcriptMode = 16843008; // 0x1010100 field public static final int transcriptMode = 16843008; // 0x1010100 field public static final int transformPivotX = 16843552; // 0x1010320 field public static final int transformPivotX = 16843552; // 0x1010320 field public static final int transformPivotY = 16843553; // 0x1010321 field public static final int transformPivotY = 16843553; // 0x1010321 Loading Loading @@ -41551,7 +41553,11 @@ package android.widget { method public java.lang.CharSequence getTextOn(); method public java.lang.CharSequence getTextOn(); method public android.graphics.drawable.Drawable getThumbDrawable(); method public android.graphics.drawable.Drawable getThumbDrawable(); method public int getThumbTextPadding(); method public int getThumbTextPadding(); method public android.content.res.ColorStateList getThumbTintList(); method public android.graphics.PorterDuff.Mode getThumbTintMode(); method public android.graphics.drawable.Drawable getTrackDrawable(); method public android.graphics.drawable.Drawable getTrackDrawable(); method public android.content.res.ColorStateList getTrackTintList(); method public android.graphics.PorterDuff.Mode getTrackTintMode(); method public void onMeasure(int, int); method public void onMeasure(int, int); method public void setShowText(boolean); method public void setShowText(boolean); method public void setSplitTrack(boolean); method public void setSplitTrack(boolean); Loading @@ -41565,8 +41571,12 @@ package android.widget { method public void setThumbDrawable(android.graphics.drawable.Drawable); method public void setThumbDrawable(android.graphics.drawable.Drawable); method public void setThumbResource(int); method public void setThumbResource(int); method public void setThumbTextPadding(int); method public void setThumbTextPadding(int); method public void setThumbTintList(android.content.res.ColorStateList); method public void setThumbTintMode(android.graphics.PorterDuff.Mode); method public void setTrackDrawable(android.graphics.drawable.Drawable); method public void setTrackDrawable(android.graphics.drawable.Drawable); method public void setTrackResource(int); method public void setTrackResource(int); method public void setTrackTintList(android.content.res.ColorStateList); method public void setTrackTintMode(android.graphics.PorterDuff.Mode); } } public class TabHost extends android.widget.FrameLayout implements android.view.ViewTreeObserver.OnTouchModeChangeListener { public class TabHost extends android.widget.FrameLayout implements android.view.ViewTreeObserver.OnTouchModeChangeListener {
core/java/android/widget/Switch.java +172 −0 Original line number Original line Diff line number Diff line Loading @@ -17,6 +17,7 @@ package android.widget; package android.widget; import android.animation.ObjectAnimator; import android.animation.ObjectAnimator; import android.annotation.Nullable; import android.content.Context; import android.content.Context; import android.content.res.ColorStateList; import android.content.res.ColorStateList; import android.content.res.Resources; import android.content.res.Resources; Loading @@ -24,6 +25,7 @@ import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.Canvas; import android.graphics.Insets; import android.graphics.Insets; import android.graphics.Paint; import android.graphics.Paint; import android.graphics.PorterDuff; import android.graphics.Rect; import android.graphics.Rect; import android.graphics.Typeface; import android.graphics.Typeface; import android.graphics.Region.Op; import android.graphics.Region.Op; Loading Loading @@ -84,7 +86,17 @@ public class Switch extends CompoundButton { private static final int MONOSPACE = 3; private static final int MONOSPACE = 3; private Drawable mThumbDrawable; private Drawable mThumbDrawable; private ColorStateList mThumbTintList = null; private PorterDuff.Mode mThumbTintMode = null; private boolean mHasThumbTint = false; private boolean mHasThumbTintMode = false; private Drawable mTrackDrawable; private Drawable mTrackDrawable; private ColorStateList mTrackTintList = null; private PorterDuff.Mode mTrackTintMode = null; private boolean mHasTrackTint = false; private boolean mHasTrackTintMode = false; private int mThumbTextPadding; private int mThumbTextPadding; private int mSwitchMinWidth; private int mSwitchMinWidth; private int mSwitchPadding; private int mSwitchPadding; Loading Loading @@ -472,6 +484,86 @@ public class Switch extends CompoundButton { return mTrackDrawable; return mTrackDrawable; } } /** * Applies a tint to the track drawable. Does not modify the current * tint mode, which is {@link PorterDuff.Mode#SRC_IN} by default. * <p> * Subsequent calls to {@link #setTrackDrawable(Drawable)} will * automatically mutate the drawable and apply the specified tint and tint * mode using {@link Drawable#setTintList(ColorStateList)}. * * @param tint the tint to apply, may be {@code null} to clear tint * * @attr ref android.R.styleable#Switch_trackTint * @see #getTrackTintList() * @see Drawable#setTintList(ColorStateList) */ public void setTrackTintList(@Nullable ColorStateList tint) { mTrackTintList = tint; mHasTrackTint = true; applyTrackTint(); } /** * @return the tint applied to the track drawable * @attr ref android.R.styleable#Switch_trackTint * @see #setTrackTintList(ColorStateList) */ @Nullable public ColorStateList getTrackTintList() { return mTrackTintList; } /** * Specifies the blending mode used to apply the tint specified by * {@link #setTrackTintList(ColorStateList)}} to the track drawable. * The default mode is {@link PorterDuff.Mode#SRC_IN}. * * @param tintMode the blending mode used to apply the tint, may be * {@code null} to clear tint * @attr ref android.R.styleable#Switch_trackTintMode * @see #getTrackTintMode() * @see Drawable#setTintMode(PorterDuff.Mode) */ public void setTrackTintMode(@Nullable PorterDuff.Mode tintMode) { mTrackTintMode = tintMode; mHasTrackTintMode = true; applyTrackTint(); } /** * @return the blending mode used to apply the tint to the track * drawable * @attr ref android.R.styleable#Switch_trackTintMode * @see #setTrackTintMode(PorterDuff.Mode) */ @Nullable public PorterDuff.Mode getTrackTintMode() { return mTrackTintMode; } private void applyTrackTint() { if (mTrackDrawable != null && (mHasTrackTint || mHasTrackTintMode)) { mTrackDrawable = mTrackDrawable.mutate(); if (mHasTrackTint) { mTrackDrawable.setTintList(mTrackTintList); } if (mHasTrackTintMode) { mTrackDrawable.setTintMode(mTrackTintMode); } // The drawable (or one of its children) may not have been // stateful before applying the tint, so let's try again. if (mTrackDrawable.isStateful()) { mTrackDrawable.setState(getDrawableState()); } } } /** /** * Set the drawable used for the switch "thumb" - the piece that the user * Set the drawable used for the switch "thumb" - the piece that the user * can physically touch and drag along the track. * can physically touch and drag along the track. Loading Loading @@ -515,6 +607,86 @@ public class Switch extends CompoundButton { return mThumbDrawable; return mThumbDrawable; } } /** * Applies a tint to the thumb drawable. Does not modify the current * tint mode, which is {@link PorterDuff.Mode#SRC_IN} by default. * <p> * Subsequent calls to {@link #setThumbDrawable(Drawable)} will * automatically mutate the drawable and apply the specified tint and tint * mode using {@link Drawable#setTintList(ColorStateList)}. * * @param tint the tint to apply, may be {@code null} to clear tint * * @attr ref android.R.styleable#Switch_thumbTint * @see #getThumbTintList() * @see Drawable#setTintList(ColorStateList) */ public void setThumbTintList(@Nullable ColorStateList tint) { mThumbTintList = tint; mHasThumbTint = true; applyThumbTint(); } /** * @return the tint applied to the thumb drawable * @attr ref android.R.styleable#Switch_thumbTint * @see #setThumbTintList(ColorStateList) */ @Nullable public ColorStateList getThumbTintList() { return mThumbTintList; } /** * Specifies the blending mode used to apply the tint specified by * {@link #setThumbTintList(ColorStateList)}} to the thumb drawable. * The default mode is {@link PorterDuff.Mode#SRC_IN}. * * @param tintMode the blending mode used to apply the tint, may be * {@code null} to clear tint * @attr ref android.R.styleable#Switch_thumbTintMode * @see #getThumbTintMode() * @see Drawable#setTintMode(PorterDuff.Mode) */ public void setThumbTintMode(@Nullable PorterDuff.Mode tintMode) { mThumbTintMode = tintMode; mHasThumbTintMode = true; applyThumbTint(); } /** * @return the blending mode used to apply the tint to the thumb * drawable * @attr ref android.R.styleable#Switch_thumbTintMode * @see #setThumbTintMode(PorterDuff.Mode) */ @Nullable public PorterDuff.Mode getThumbTintMode() { return mThumbTintMode; } private void applyThumbTint() { if (mThumbDrawable != null && (mHasThumbTint || mHasThumbTintMode)) { mThumbDrawable = mThumbDrawable.mutate(); if (mHasThumbTint) { mThumbDrawable.setTintList(mThumbTintList); } if (mHasThumbTintMode) { mThumbDrawable.setTintMode(mThumbTintMode); } // The drawable (or one of its children) may not have been // stateful before applying the tint, so let's try again. if (mThumbDrawable.isStateful()) { mThumbDrawable.setState(getDrawableState()); } } } /** /** * Specifies whether the track should be split by the thumb. When true, * 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, * the thumb's optical bounds will be clipped out of the track drawable, Loading
core/res/res/values/attrs.xml +26 −0 Original line number Original line Diff line number Diff line Loading @@ -7261,8 +7261,34 @@ <declare-styleable name="Switch"> <declare-styleable name="Switch"> <!-- Drawable to use as the "thumb" that switches back and forth. --> <!-- Drawable to use as the "thumb" that switches back and forth. --> <attr name="thumb" /> <attr name="thumb" /> <!-- Tint to apply to the thumb. --> <attr name="thumbTint" /> <!-- Blending mode used to apply the thumb tint. --> <attr name="thumbTintMode" /> <!-- Drawable to use as the "track" that the switch thumb slides within. --> <!-- Drawable to use as the "track" that the switch thumb slides within. --> <attr name="track" format="reference" /> <attr name="track" format="reference" /> <!-- Tint to apply to the track. --> <attr name="trackTint" format="color" /> <!-- Blending mode used to apply the track tint. --> <attr name="trackTintMode"> <!-- The tint is drawn on top of the drawable. [Sa + (1 - Sa)*Da, Rc = Sc + (1 - Sa)*Dc] --> <enum name="src_over" value="3" /> <!-- The tint is masked by the alpha channel of the drawable. The drawable’s color channels are thrown out. [Sa * Da, Sc * Da] --> <enum name="src_in" value="5" /> <!-- The tint is drawn above the drawable, but with the drawable’s alpha channel masking the result. [Da, Sc * Da + (1 - Sa) * Dc] --> <enum name="src_atop" value="9" /> <!-- Multiplies the color and alpha channels of the drawable with those of the tint. [Sa * Da, Sc * Dc] --> <enum name="multiply" value="14" /> <!-- [Sa + Da - Sa * Da, Sc + Dc - Sc * Dc] --> <enum name="screen" value="15" /> <!-- Combines the tint and drawable color and alpha channels, clamping the result to valid color values. Saturate(S + D) --> <enum name="add" value="16" /> </attr> <!-- Text to use when the switch is in the checked/"on" state. --> <!-- Text to use when the switch is in the checked/"on" state. --> <attr name="textOn" /> <attr name="textOn" /> <!-- Text to use when the switch is in the unchecked/"off" state. --> <!-- Text to use when the switch is in the unchecked/"off" state. --> Loading
core/res/res/values/public.xml +3 −0 Original line number Original line Diff line number Diff line Loading @@ -2608,6 +2608,9 @@ =============================================================== --> =============================================================== --> <eat-comment /> <eat-comment /> <public type="attr" name="trackTint" /> <public type="attr" name="trackTintMode" /> <public type="style" name="Widget.Material.Button.Colored" /> <public type="style" name="Widget.Material.Button.Colored" /> </resources> </resources>