Make selection follow theme

This commit is contained in:
MrLetsplay 2023-09-21 21:27:29 +02:00
parent 7b6dccb2ff
commit 7be7e0e11e
Signed by: mr
SSH Key Fingerprint: SHA256:92jBH80vpXyaZHjaIl47pjRq+Yt7XGTArqQg1V7hSqg
3 changed files with 11 additions and 4 deletions

View File

@ -1,6 +1,7 @@
package com.cringe_studios.cringe_authenticator.grouplist; package com.cringe_studios.cringe_authenticator.grouplist;
import android.content.res.ColorStateList; import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.ColorDrawable;
import android.os.Build; import android.os.Build;
@ -40,7 +41,10 @@ public class GroupListItem extends RecyclerView.ViewHolder {
this.selected = selected; this.selected = selected;
if(selected) { if(selected) {
binding.menuItemBackground.setBackground(new ColorDrawable(binding.getRoot().getContext().getResources().getColor(R.color.selected_highlight))); TypedArray array = binding.getRoot().getContext().getTheme().obtainStyledAttributes(new int[] { R.attr.colorTheme1 });
int color = array.getColor(0, 0xFFFF00FF);
color = Color.argb(0x55, Color.red(color), Color.green(color), Color.blue(color));
binding.menuItemBackground.setBackground(new ColorDrawable(color));
}else { }else {
binding.menuItemBackground.setBackground(null); binding.menuItemBackground.setBackground(null);
} }

View File

@ -1,5 +1,7 @@
package com.cringe_studios.cringe_authenticator.otplist; package com.cringe_studios.cringe_authenticator.otplist;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.ColorDrawable;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -52,7 +54,10 @@ public class OTPListItem extends RecyclerView.ViewHolder {
this.selected = selected; this.selected = selected;
if(selected) { if(selected) {
binding.otpCodeBackground.setBackground(new ColorDrawable(binding.getRoot().getContext().getResources().getColor(R.color.selected_highlight))); TypedArray array = binding.getRoot().getContext().getTheme().obtainStyledAttributes(new int[] { R.attr.colorTheme1 });
int color = array.getColor(0, 0xFFFF00FF);
color = Color.argb(0x55, Color.red(color), Color.green(color), Color.blue(color));
binding.otpCodeBackground.setBackground(new ColorDrawable(color));
}else { }else {
binding.otpCodeBackground.setBackground(null); binding.otpCodeBackground.setBackground(null);
} }

View File

@ -16,6 +16,4 @@
<color name="color_yellow">#FFE500</color> <color name="color_yellow">#FFE500</color>
<color name="color_turquoise">#00FFF7</color> <color name="color_turquoise">#00FFF7</color>
<color name="color_green">#00FF0A</color> <color name="color_green">#00FF0A</color>
<color name="selected_highlight">#33008BFF</color>
</resources> </resources>