Java Code Examples for android.widget.Switch#setThumbDrawable()

The following examples show how to use android.widget.Switch#setThumbDrawable() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RadiusSwitchDelegate.java    From UIWidget with Apache License 2.0 6 votes vote down vote up
/**
 * 设置Drawable相关属性
 */
private void setSwitchDrawable() {
    mSwitch = (Switch) mView;
    mStateThumbDrawable = new StateListDrawable();
    mStateTrackDrawable = new StateListDrawable();
    mStateThumbDrawable.addState(new int[]{mStateChecked}, getStateDrawable(mThumbCheckedDrawable, mThumbRadius, mThumbDrawableWidth, mThumbDrawableHeight, mThumbStrokeWidth, mThumbStrokeCheckedColor));
    mStateThumbDrawable.addState(new int[]{mStateSelected}, getStateDrawable(mThumbSelectedDrawable, mThumbRadius, mThumbDrawableWidth, mThumbDrawableHeight, mThumbStrokeWidth, mThumbStrokeSelectedColor));
    mStateThumbDrawable.addState(new int[]{mStatePressed}, getStateDrawable(mThumbPressedDrawable, mThumbRadius, mThumbDrawableWidth, mThumbDrawableHeight, mThumbStrokeWidth, mThumbStrokePressedColor));
    mStateThumbDrawable.addState(new int[]{mStateDisabled}, getStateDrawable(mThumbDisabledDrawable, mThumbRadius, mThumbDrawableWidth, mThumbDrawableHeight, mThumbStrokeWidth, mThumbStrokeDisabledColor));
    mStateThumbDrawable.addState(new int[]{}, getStateDrawable(mThumbDrawable, mThumbRadius, mThumbDrawableWidth, mThumbDrawableHeight, mThumbStrokeWidth, mThumbStrokeColor));

    mTrackDrawableHeight = 0;
    mStateTrackDrawable.addState(new int[]{mStateChecked}, getStateDrawable(mTrackCheckedDrawable, mTrackRadius, mTrackDrawableWidth, mTrackDrawableHeight, mTrackStrokeWidth, mTrackStrokeCheckedColor));
    mStateTrackDrawable.addState(new int[]{mStateSelected}, getStateDrawable(mTrackSelectedDrawable, mTrackRadius, mTrackDrawableWidth, mTrackDrawableHeight, mTrackStrokeWidth, mTrackStrokeSelectedColor));
    mStateTrackDrawable.addState(new int[]{mStatePressed}, getStateDrawable(mTrackPressedDrawable, mTrackRadius, mTrackDrawableWidth, mTrackDrawableHeight, mTrackStrokeWidth, mTrackStrokePressedColor));
    mStateTrackDrawable.addState(new int[]{mStateDisabled}, getStateDrawable(mTrackDisabledDrawable, mTrackRadius, mTrackDrawableWidth, mTrackDrawableHeight, mTrackStrokeWidth, mTrackStrokeDisabledColor));
    mStateTrackDrawable.addState(new int[]{}, getStateDrawable(mTrackDrawable, mTrackRadius, mTrackDrawableWidth, mTrackDrawableHeight, mTrackStrokeWidth, mTrackStrokeColor));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        mSwitch.setThumbDrawable(mStateThumbDrawable);
        mSwitch.setTrackDrawable(mStateTrackDrawable);
    }
}
 
Example 2
Source File: TintHelper.java    From a with GNU General Public License v3.0 5 votes vote down vote up
public static void setTint(@NonNull Switch switchView, @ColorInt int color, boolean useDarker) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) return;
    if (switchView.getTrackDrawable() != null) {
        switchView.setTrackDrawable(modifySwitchDrawable(switchView.getContext(),
                switchView.getTrackDrawable(), color, false, false, useDarker));
    }
    if (switchView.getThumbDrawable() != null) {
        switchView.setThumbDrawable(modifySwitchDrawable(switchView.getContext(),
                switchView.getThumbDrawable(), color, true, false, useDarker));
    }
}
 
Example 3
Source File: TintHelper.java    From MyBookshelf with GNU General Public License v3.0 5 votes vote down vote up
public static void setTint(@NonNull Switch switchView, @ColorInt int color, boolean useDarker) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) return;
    if (switchView.getTrackDrawable() != null) {
        switchView.setTrackDrawable(modifySwitchDrawable(switchView.getContext(),
                switchView.getTrackDrawable(), color, false, false, useDarker));
    }
    if (switchView.getThumbDrawable() != null) {
        switchView.setThumbDrawable(modifySwitchDrawable(switchView.getContext(),
                switchView.getThumbDrawable(), color, true, false, useDarker));
    }
}
 
Example 4
Source File: TintHelper.java    From APlayer with GNU General Public License v3.0 5 votes vote down vote up
public static void setTint(@NonNull Switch switchView, @ColorInt int color, boolean useDarker) {
  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
    return;
  }
  if (switchView.getTrackDrawable() != null) {
    switchView.setTrackDrawable(modifySwitchDrawable(switchView.getContext(),
        switchView.getTrackDrawable(), color, false, false, useDarker));
  }
  if (switchView.getThumbDrawable() != null) {
    switchView.setThumbDrawable(modifySwitchDrawable(switchView.getContext(),
        switchView.getThumbDrawable(), color, true, false, useDarker));
  }
}