Java Code Examples for android.widget.RadioButton#setButtonTintList()

The following examples show how to use android.widget.RadioButton#setButtonTintList() . 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: TintHelper.java    From a with GNU General Public License v3.0 6 votes vote down vote up
public static void setTint(@NonNull RadioButton radioButton, @ColorInt int color, boolean useDarker) {
    ColorStateList sl = new ColorStateList(new int[][]{
            new int[]{-android.R.attr.state_enabled},
            new int[]{android.R.attr.state_enabled, -android.R.attr.state_checked},
            new int[]{android.R.attr.state_enabled, android.R.attr.state_checked}
    }, new int[]{
            // Rdio button includes own alpha for disabled state
            ColorUtil.stripAlpha(ContextCompat.getColor(radioButton.getContext(), useDarker ? R.color.ate_control_disabled_dark : R.color.ate_control_disabled_light)),
            ContextCompat.getColor(radioButton.getContext(), useDarker ? R.color.ate_control_normal_dark : R.color.ate_control_normal_light),
            color
    });
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        radioButton.setButtonTintList(sl);
    } else {
        Drawable d = createTintedDrawable(ContextCompat.getDrawable(radioButton.getContext(), R.drawable.abc_btn_radio_material), sl);
        radioButton.setButtonDrawable(d);
    }
}
 
Example 2
Source File: TintHelper.java    From MyBookshelf with GNU General Public License v3.0 6 votes vote down vote up
public static void setTint(@NonNull RadioButton radioButton, @ColorInt int color, boolean useDarker) {
    ColorStateList sl = new ColorStateList(new int[][]{
            new int[]{-android.R.attr.state_enabled},
            new int[]{android.R.attr.state_enabled, -android.R.attr.state_checked},
            new int[]{android.R.attr.state_enabled, android.R.attr.state_checked}
    }, new int[]{
            // Radio button includes own alpha for disabled state
            ColorUtil.stripAlpha(ContextCompat.getColor(radioButton.getContext(), useDarker ? R.color.ate_control_disabled_dark : R.color.ate_control_disabled_light)),
            ContextCompat.getColor(radioButton.getContext(), useDarker ? R.color.ate_control_normal_dark : R.color.ate_control_normal_light),
            color
    });
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        radioButton.setButtonTintList(sl);
    } else {
        Drawable d = createTintedDrawable(ContextCompat.getDrawable(radioButton.getContext(), R.drawable.abc_btn_radio_material), sl);
        radioButton.setButtonDrawable(d);
    }
}
 
Example 3
Source File: Easel.java    From andela-crypto-app with Apache License 2.0 6 votes vote down vote up
/**
 * Tint the radio button
 *
 * @param radioButton the radio button
 * @param color       the color
 */
public static void tint(@NonNull RadioButton radioButton, @ColorInt int color) {
    final int disabledColor = getDisabledColor(radioButton.getContext());
    ColorStateList sl = new ColorStateList(new int[][]{
            new int[]{android.R.attr.state_enabled, -android.R.attr.state_checked},
            new int[]{android.R.attr.state_enabled, android.R.attr.state_checked},
            new int[]{-android.R.attr.state_enabled, -android.R.attr.state_checked},
            new int[]{-android.R.attr.state_enabled, android.R.attr.state_checked}
    }, new int[]{
            getThemeAttrColor(radioButton.getContext(), R.attr.colorControlNormal),
            color,
            disabledColor,
            disabledColor
    });
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        radioButton.setButtonTintList(sl);
    } else {
        Drawable radioDrawable = ContextCompat.getDrawable(radioButton.getContext(), R.drawable.abc_btn_radio_material);
        Drawable d = DrawableCompat.wrap(radioDrawable);
        DrawableCompat.setTintList(d, sl);
        radioButton.setButtonDrawable(d);
    }
}
 
Example 4
Source File: MDTintHelper.java    From NewsMe with Apache License 2.0 6 votes vote down vote up
public static void setTint(@NonNull RadioButton radioButton, @ColorInt int color) {
    ColorStateList sl = new ColorStateList(new int[][]{
            new int[]{-android.R.attr.state_checked},
            new int[]{android.R.attr.state_checked}
    }, new int[]{
            ThemeHelper.resolveColor(radioButton.getContext(), R.attr.colorControlNormal),
            color
    });
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        radioButton.setButtonTintList(sl);
    } else {
        Drawable d = DrawableCompat.wrap(ContextCompat.getDrawable(radioButton.getContext(), R.drawable.abc_btn_radio_material));
        DrawableCompat.setTintList(d, sl);
        radioButton.setButtonDrawable(d);
    }
}
 
Example 5
Source File: MDTintHelper.java    From talk-android with MIT License 6 votes vote down vote up
@SuppressLint("NewApi")
public static void setTint(RadioButton radioButton, int color) {
    ColorStateList sl = new ColorStateList(new int[][]{
            new int[]{-android.R.attr.state_checked},
            new int[]{android.R.attr.state_checked}
    }, new int[]{
            DialogUtils.resolveColor(radioButton.getContext(), R.attr.colorControlNormal),
            color
    });
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        radioButton.setButtonTintList(sl);
    } else {
        Drawable d = DrawableCompat.wrap(ContextCompat.getDrawable(radioButton.getContext(), R.drawable.abc_btn_radio_material));
        DrawableCompat.setTintList(d, sl);
        radioButton.setButtonDrawable(d);
    }
}
 
Example 6
Source File: TintHelper.java    From APlayer with GNU General Public License v3.0 6 votes vote down vote up
public static void setTint(@NonNull RadioButton radioButton, @ColorInt int color,
    boolean useDarker) {
  ColorStateList sl = new ColorStateList(new int[][]{
      new int[]{-android.R.attr.state_enabled},
      new int[]{android.R.attr.state_enabled, -android.R.attr.state_checked},
      new int[]{android.R.attr.state_enabled, android.R.attr.state_checked}
  }, new int[]{
      // Rdio button includes own alpha for disabled state
      ColorUtil.stripAlpha(ContextCompat.getColor(radioButton.getContext(),
          useDarker ? R.color.ate_control_disabled_dark : R.color.ate_control_disabled_light)),
      ContextCompat.getColor(radioButton.getContext(),
          useDarker ? R.color.ate_control_normal_dark : R.color.ate_control_normal_light),
      color
  });
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    radioButton.setButtonTintList(sl);
  } else {
    Drawable d = createTintedDrawable(
        ContextCompat.getDrawable(radioButton.getContext(), R.drawable.abc_btn_radio_material),
        sl);
    radioButton.setButtonDrawable(d);
  }
}
 
Example 7
Source File: EmTintUtils.java    From AndroidTint with Apache License 2.0 6 votes vote down vote up
public static void setTint(@NonNull RadioButton radioButton, @ColorInt int color) {
    ColorStateList sl = new ColorStateList(new int[][]{
            new int[]{-android.R.attr.state_checked},
            new int[]{android.R.attr.state_checked}
    }, new int[]{
            ThemeHelper.resolveColor(radioButton.getContext(), R.attr.colorControlNormal),
            color
    });
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        radioButton.setButtonTintList(sl);
    } else {
        Drawable d = DrawableCompat.wrap(ContextCompat.getDrawable(radioButton.getContext(), R.drawable.abc_btn_radio_material));
        DrawableCompat.setTintList(d, sl);
        radioButton.setButtonDrawable(d);
    }
}
 
Example 8
Source File: DeviceFragment.java    From android-showcase-template with Apache License 2.0 5 votes vote down vote up
/**
 * Function to allow updates to the radio buttons UI when a security check has failed Passed
 * tests do not need updating due to being the default UI state
 *
 * @param uiElement - the UI element to update
 * @param textResource - the text resource to set the updates text for
 */
public void setCheckFailed(RadioButton uiElement, int textResource) {
    totalTestFailures++;
    uiElement.setText(textResource);
    uiElement.setTextColor(getResources().getColor(R.color.red));
    uiElement.setButtonDrawable(R.drawable.baseline_warning);
    uiElement.setButtonTintList(ColorStateList.valueOf(getResources().getColor(R.color.red)));

}
 
Example 9
Source File: ThemePreference.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent) {

    if (convertView == null) {
        final ViewGroup nullParent = null;
        convertView = mLayoutInflater.inflate(R.layout.theme_dialog, nullParent);
    }

    String theme = themeOptions[position];

    TextView txtView = convertView.findViewById(R.id.title);
    txtView.setText(theme);

    RadioButton radioButton = convertView.findViewById(R.id.radio);

    int itemColor = ContextCompat.getColor(context, resolveColor(position));

    ColorStateList colorStateList = new ColorStateList(
            new int[][]{
                    new int[]{android.R.attr.state_enabled}, //enabled
                    new int[]{android.R.attr.state_enabled} //disabled

            },
            new int[]{itemColor, itemColor}
    );

    txtView.setShadowLayer(1.5f, -1, 1, itemColor);
    radioButton.setButtonTintList(colorStateList);

    radioButton.setChecked(themeValues[position].equals(selectedTheme));
    return convertView;
}
 
Example 10
Source File: ThemeHelper.java    From Liz with GNU General Public License v3.0 4 votes vote down vote up
public void themeRadioButton(RadioButton radioButton) {
	if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
		radioButton.setButtonTintList(getTintList());
		radioButton.setTextColor(getTextColor());
	}
}
 
Example 11
Source File: ThemeHelper.java    From Android-AudioRecorder-App with Apache License 2.0 4 votes vote down vote up
public void themeRadioButton(RadioButton radioButton) {
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    radioButton.setButtonTintList(getTintList());
    radioButton.setTextColor(getTextColor());
  }
}