Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Appcompact DialogFragment single-choice checkmark color

I have a problem. My activity has style

<style name="MaterialTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimary">@color/action_bar_background</item>
    <item name="colorPrimaryDark">@color/action_bar_background</item>
    <item name="colorAccent">@color/action_bar_background</item>
</style>

also i have dialogFragment with simple single-choice chooser.

@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
    final AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity());
    dialog.setTitle(R.string.image_resolution);
    dialog.setSingleChoiceItems(R.array.quality_labels, getPosition(), this);
    return dialog.create();
}

How to change color of picker checkmarks (green circles) ???enter image description here

like image 884
Artem Garkusha Avatar asked Mar 03 '15 19:03

Artem Garkusha


3 Answers

You must create corresponding style for AlertDialog

<style name="MaterialThemeDialog" parent="Theme.AppCompat.Light.Dialog.Alert">
    <item name="colorAccent">@color/action_bar_background</item>
</style>

and pass it to AlertDialog.Builder constructor

@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
    final AlertDialog.Builder dialog = new AlertDialog.Builder(
            getActivity(),
            R.style.MaterialThemeDialog);
    dialog.setTitle(R.string.image_resolution);
    dialog.setSingleChoiceItems(R.array.quality_labels, getPosition(), this);
    return dialog.create();
}
like image 168
Pawel Czechowski Avatar answered Oct 18 '22 03:10

Pawel Czechowski


You can reference a custom radio button through the ListAdapter argument in AlertDialog.Builder.setSingleChoiceItems(ListAdapter, int, OnClickListener).

The answer in this SO post nails the details: Android Alert Dialog replace default blue with another color

For help with creating your custom components check out: http://android-holo-colors.com

like image 24
peterrhodesdev Avatar answered Oct 18 '22 04:10

peterrhodesdev


1) Create a new xml, where checkMark is the style and animation of the checkmark, and the checkMarkTint is the color of the checkmark

<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:gravity="center_vertical"
android:paddingEnd="16dip"
android:layout_marginTop="10dp"
android:paddingStart="16dip"
android:textSize="14sp"
android:checkMark=""="?android:attr/listChoiceIndicatorSingle"
android:checkMarkTint="@color/your_checkmark_color"
android:textColor="@color/your_text_color" />

2) Then create an adapter above your alerDialog.SetSingleChoiceItems

ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(getApplicationContext(),R.layout.your_custom_layout, charSequenceList);

3) Add the adapter

alerDialog.setSingleChoiceItems(adapter, -1, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    //.. 

            });
like image 1
Ashky Avatar answered Oct 18 '22 04:10

Ashky