如何在AlertDialog.Builder AppCompat中更改Items的颜色?

Nic*_*hek 5 android text colors android-appcompat android-alertdialog

如何在AlertDialog.Builder AppCompat中更改Items的颜色?

我想将textColor项目(照片,gallary)设置为其他任何项目.

这是我的代码:

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.AppCompatAlertDialogStyle);
        builder.setTitle(getResources().getString(R.string.choose_image_source));
        builder.setItems(new CharSequence[]{getResources()
                        .getString(R.string.photo), getResources()
                        .getString(R.string.camera)}, new DialogInterface.OnClickListener() {
Run Code Online (Sandbox Code Playgroud)

...

<style name="AppCompatAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">

        <item name="colorAccent">#000000</item><!-- buttons OK cancel-->
        <item name="android:textColorPrimary">#696969</item><!--text in message-->
        <item name="android:background">#f0a400</item> <!-- all bg-->
    </style>
    <style name="MyTitleTextStyle">
        <item name="android:textColor">#000000</item><!-- title color-->
        <item name="android:textAppearance">@style/TextAppearance.AppCompat.Title</item>
    </style>
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

小智 6

试试这个:

<style name="AppCompatAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
    <item name="colorAccent">#000000</item><!-- buttons OK cancel-->
    <item name="android:textColorPrimary">#696969</item><!--text in message-->
    <item name="android:background">#f0a400</item> <!-- all bg-->
    <!-- items color -->
    <item name="textColorAlertDialogListItem">#33b5e5</item>
</style>
<style name="MyTitleTextStyle">
    <item name="android:textColor">#000000</item><!-- title color-->
    <item name="android:textAppearance">@style/TextAppearance.AppCompat.Title</item>
</style>
Run Code Online (Sandbox Code Playgroud)


Kis*_*oid 0

我也遇到了同样的问题。解决这个问题的唯一方法是扩展我自己的布局版本。我发现在你的例子中它是一个 AlertDialog。我建议您做的是创建一个独特的类,即您自定义的 AlertDialog 并为此创建一个布局,然后对其进行膨胀。

这是一篇对我帮助很大的帖子。http://blog.androgames.net/10/custom-android-dialog/

我按照这篇文章解决了自定义对话框的问题。

如果您还有更多疑问,请告诉我。

谢谢。