Java Code Examples for android.support.v7.widget.SwitchCompat#setThumbTintList()

The following examples show how to use android.support.v7.widget.SwitchCompat#setThumbTintList() . 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: MDTintUtil.java    From LLApp with Apache License 2.0 5 votes vote down vote up
public static void setTint(@NonNull SwitchCompat switchCompat, @ColorInt int color) {
    int[] colors = new int[]{color, Color.rgb(236, 236, 236), Color.rgb(236, 236, 236), Color.rgb(236, 236, 236), Color.rgb(236, 236, 236), Color.rgb(236, 236, 236)};
    int[][] states = new int[6][];
    states[0] = new int[]{android.R.attr.state_checked, android.R.attr.state_enabled};
    states[1] = new int[]{android.R.attr.state_enabled, android.R.attr.state_focused};
    states[2] = new int[]{android.R.attr.state_enabled};
    states[3] = new int[]{android.R.attr.state_focused};
    states[4] = new int[]{android.R.attr.state_window_focused};
    states[5] = new int[]{};
    switchCompat.setThumbTintList(new ColorStateList(states, colors));
}
 
Example 2
Source File: MDTintUtil.java    From UGank with GNU General Public License v3.0 5 votes vote down vote up
public static void setTint(@NonNull SwitchCompat switchCompat, @ColorInt int color) {
    int[] colors = new int[]{color, Color.rgb(236, 236, 236), Color.rgb(236, 236, 236), Color.rgb(236, 236, 236), Color.rgb(236, 236, 236), Color.rgb(236, 236, 236)};
    int[][] states = new int[6][];
    states[0] = new int[]{android.R.attr.state_checked, android.R.attr.state_enabled};
    states[1] = new int[]{android.R.attr.state_enabled, android.R.attr.state_focused};
    states[2] = new int[]{android.R.attr.state_enabled};
    states[3] = new int[]{android.R.attr.state_focused};
    states[4] = new int[]{android.R.attr.state_window_focused};
    states[5] = new int[]{};
    switchCompat.setThumbTintList(new ColorStateList(states, colors));
}
 
Example 3
Source File: SwitchCompatColorAdapter.java    From Scoops with Apache License 2.0 5 votes vote down vote up
@Override
public void applyColor(SwitchCompat view, @ColorInt int color) {
    if(disabledColor == 0) disabledColor = AttrUtils.getColorAttr(view.getContext(), R.attr.colorSwitchThumbNormal);
    if(trackDisabledColor == 0) trackDisabledColor = view.getContext().getResources().getColor(R.color.grey_600);
    view.setThumbTintList(Utils.colorToStateList(color, disabledColor));
    view.setTrackTintList(Utils.colorToStateList(color, trackDisabledColor));
}
 
Example 4
Source File: AlarmRepeatDialog.java    From SuntimesWidget with GNU General Public License v3.0 4 votes vote down vote up
/**
 *
 */
protected void initViews( final Context context, View dialogContent )
{
    SuntimesUtils.initDisplayStrings(context);

    if (Build.VERSION.SDK_INT >= 14)
    {
        switchRepeat = (SwitchCompat) dialogContent.findViewById(R.id.alarmOption_repeat);
        if (switchRepeat != null)
        {
            switchRepeat.setOnCheckedChangeListener(onRepeatChanged);
            if (colorOverrides[0] != -1) {
                switchRepeat.setThumbTintList(SuntimesUtils.colorStateList(
                        colorOverrides[0],
                        colorOverrides[1],
                        colorOverrides[2],
                        colorOverrides[3]));
                switchRepeat.setTrackTintList(SuntimesUtils.colorStateList(
                        ColorUtils.setAlphaComponent(colorOverrides[0], 85),
                        ColorUtils.setAlphaComponent(colorOverrides[1], 85),
                        ColorUtils.setAlphaComponent(colorOverrides[2], 85),
                        ColorUtils.setAlphaComponent(colorOverrides[3], 85)));  // 33% alpha (85 / 255)
            }
        }

    } else {
        checkRepeat = (CheckBox) dialogContent.findViewById(R.id.alarmOption_repeat);
        if (checkRepeat != null) {
            checkRepeat.setOnCheckedChangeListener(onRepeatChanged);
            CompoundButtonCompat.setButtonTintList(checkRepeat, SuntimesUtils.colorStateList(colorOverrides[0], colorOverrides[1], colorOverrides[2], colorOverrides[3]));
        }
    }

    btnDays = new SparseArray<>();
    btnDays.put(Calendar.SUNDAY, (ToggleButton)dialogContent.findViewById(R.id.alarmOption_repeat_sun));
    btnDays.put(Calendar.MONDAY, (ToggleButton)dialogContent.findViewById(R.id.alarmOption_repeat_mon));
    btnDays.put(Calendar.TUESDAY, (ToggleButton)dialogContent.findViewById(R.id.alarmOption_repeat_tue));
    btnDays.put(Calendar.WEDNESDAY, (ToggleButton)dialogContent.findViewById(R.id.alarmOption_repeat_wed));
    btnDays.put(Calendar.THURSDAY, (ToggleButton)dialogContent.findViewById(R.id.alarmOption_repeat_thu));
    btnDays.put(Calendar.FRIDAY, (ToggleButton)dialogContent.findViewById(R.id.alarmOption_repeat_fri));
    btnDays.put(Calendar.SATURDAY, (ToggleButton)dialogContent.findViewById(R.id.alarmOption_repeat_sat));

    int n = btnDays.size();
    for (int i=0; i<n; i++)
    {
        int day = btnDays.keyAt(i);
        ToggleButton button = btnDays.get(day);
        if (button != null)
        {
            button.setOnCheckedChangeListener(onRepeatDayChanged);
            String dayName = utils.getShortDayString(context, day);
            button.setTextOn(dayName);
            button.setTextOff(dayName);
        }
    }
}