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

6

如何修改AlertDialog.Builder AppCompat中项目的颜色?

我想将项目(照片,图库)的文本颜色修改为其他颜色。

这是我的代码:

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() {

...

<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>

enter image description here


在对话框中填充自定义布局。 - KishuDroid
你可以创建自定义警告对话框 - https://dev59.com/AHE85IYBdhLWcg3wZyqt,以下链接可能会有所帮助:1)http://stackoverflow.com/questions/12938835/change-background-textcolor-of-alertdialog 2)https://dev59.com/HmQo5IYBdhLWcg3wQdet - AsfK
1
@user3559670,这个操作是无用的,需要执行太多的操作。 - NickUnuchek
2个回答

5

试试这个:

<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>

1
它应该是“android:textColorAlertDialogListItem”。 - Tommy Ovesen

0

我之前也遇到过同样的问题。解决它的唯一方法是扩展自己版本的布局。我看到你的情况是AlertDialog。我建议你创建一个独特的类,即自定义的AlertDialog,并为此创建一个布局,然后再进行填充。

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

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

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

谢谢。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接