6

How to change color of Items in AlertDialog.Builder AppCompat ?

I want to set textColor of items(photo,gallary) to any other.

here is my code:

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

NickUnuchek
  • 11,794
  • 12
  • 98
  • 138
  • inflate custom layout in dialog. – KishuDroid Sep 17 '15 at 11:39
  • you can create custom alert dialog - http://stackoverflow.com/questions/2795300/how-to-implement-a-custom-alertdialog-view and those links can be helpful: 1) http://stackoverflow.com/questions/12938835/change-background-textcolor-of-alertdialog 2) http://stackoverflow.com/questions/16200914/alertdialog-styling-how-to-change-style-color-of-title-message-etc – AsfK Sep 17 '15 at 11:40
  • 1
    @user3559670 , useless, too many operations to do it. – NickUnuchek Sep 17 '15 at 11:43

2 Answers2

5

Try this:

<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>
Daniel Wang
  • 51
  • 1
  • 3
0

I kinda faced the same problem. And the only way to solve it was extending my own version of layout. I see that in your case it is an AlertDialog. What I recommend you to do, is to create a unique class, that is your customized AlertDialog and create a layout for this, and then you inflate this.

Here is a post that helped me a lot. http://blog.androgames.net/10/custom-android-dialog/

I followed this post and solved my problem with customizing dialogs.

Please, if you have more doubts, let me know.

Thanks.

KishuDroid
  • 5,411
  • 4
  • 30
  • 47