Appcompact DialogFragment single-choice checkmark color

柔情痞子 提交于 2021-02-18 06:42:07

问题


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


回答1:


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();
}



回答2:


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




回答3:


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) {
                    //.. 

            });


来源:https://stackoverflow.com/questions/28840700/appcompact-dialogfragment-single-choice-checkmark-color

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!