Skip to content

Commit

Permalink
Use TextViewCompat.setCompoundDrawableTintList().
Browse files Browse the repository at this point in the history
  • Loading branch information
Isira-Seneviratne committed Aug 5, 2022
1 parent 507ec76 commit 2070078
Showing 1 changed file with 10 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
import android.content.res.ColorStateList;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
Expand All @@ -21,7 +21,7 @@
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.content.res.AppCompatResources;
import androidx.core.graphics.drawable.DrawableCompat;
import androidx.core.widget.TextViewCompat;
import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder;

Expand Down Expand Up @@ -215,17 +215,14 @@ void openActionChooserDialog() {
.getRoot();

// if present set action icon with correct color
if (NotificationConstants.ACTION_ICONS[action] != 0) {
Drawable drawable = AppCompatResources.getDrawable(getContext(),
NotificationConstants.ACTION_ICONS[action]);
if (drawable != null) {
final int color = ThemeHelper.resolveColorFromAttr(getContext(),
android.R.attr.textColorPrimary);
drawable = DrawableCompat.wrap(drawable).mutate();
drawable.setTint(color);
radioButton.setCompoundDrawablesRelativeWithIntrinsicBounds(null,
null, drawable, null);
}
final int iconId = NotificationConstants.ACTION_ICONS[action];
if (iconId != 0) {
radioButton.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0,
iconId, 0);

final var color = ColorStateList.valueOf(ThemeHelper
.resolveColorFromAttr(getContext(), android.R.attr.textColorPrimary));
TextViewCompat.setCompoundDrawableTintList(radioButton, color);
}

radioButton.setText(NotificationConstants.getActionName(getContext(), action));
Expand Down

0 comments on commit 2070078

Please sign in to comment.