Apply Dialog Box

I have a problem. My activity has a 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> 

I also have a dialog box with a simple selection one by one selection.

 @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 the color of the selection control points (green circles) enter image description here

+5
source share
3 answers

You must create an appropriate 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 the constructor AlertDialog.Builder

 @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(); } 
+6
source

You can reference a custom switch using the ListAdapter argument in AlertDialog.Builder.setSingleChoiceItems(ListAdapter, int, OnClickListener) .

The answer in this SO post details: Android Alert Dialog replace blue by default with a different color

For help creating custom components, follow these steps: http://android-holo-colors.com

+1
source

1) Create a new xml where checkMark is the style and animation of the checkmark, and 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 an adapter

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

Source: https://habr.com/ru/post/1214602/


All Articles