Make Preferences more visible with colored rounded rectangle background and an arrow icon

Bug: 320709814
Test: atest ArrowPreferenceTest
Change-Id: Id1ed44554010ae0df901cceba2624a1b56661df6
This commit is contained in:
jasonwshsu
2024-01-29 16:51:17 +08:00
committed by Jason Hsu
parent 6dc0e30b56
commit d23c2867c6
5 changed files with 95 additions and 23 deletions

View File

@@ -22,17 +22,25 @@ import android.util.AttributeSet;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.res.TypedArrayUtils;
import androidx.preference.Preference;
import com.android.settings.R;
/**
* A settings preference with colored rounded rectangle background and an arrow icon on the right
* A settings preference with colored rounded rectangle background and an arrow icon on the right.
*/
public class ArrowPreference extends Preference {
public class ArrowPreference extends BackgroundPreference {
public ArrowPreference(@NonNull Context context) {
this(context, null);
public ArrowPreference(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr,
int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
setBackground(
com.android.settingslib.widget.mainswitch.R.drawable.settingslib_switch_bar_bg_on);
setWidgetLayoutResource(R.layout.preference_widget_arrow);
}
public ArrowPreference(@NonNull Context context, @Nullable AttributeSet attrs,
int defStyleAttr) {
this(context, attrs, defStyleAttr, 0);
}
public ArrowPreference(@NonNull Context context, @Nullable AttributeSet attrs) {
@@ -41,18 +49,7 @@ public class ArrowPreference extends Preference {
android.R.attr.preferenceStyle));
}
public ArrowPreference(@NonNull Context context, @Nullable AttributeSet attrs,
int defStyleAttr) {
this(context, attrs, defStyleAttr, 0);
}
public ArrowPreference(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr,
int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init();
}
private void init() {
setLayoutResource(R.layout.arrow_preference);
public ArrowPreference(@NonNull Context context) {
this(context, null);
}
}