2

color/colorPrimary is some orange color I want header has it. But I succeded to change header text color which is easy . I would like to change color of header background. This is what I have so far:

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

    <item name="android:textColorPrimary">@color/colorPrimary</item>
    <item name="android:windowTitleBackgroundStyle">@style/dialog_title_style</item>
    <item name="android:alertDialogStyle">@style/AlertDialog_Sphinx</item>
    <item name="colorAccent">@color/colorPrimary</item>




</style>
<style name="dialog_title_style" >
    <item name="android:background">@color/colorPrimary</item>
    <item name="android:padding">100dp</item>
</style>

<style name="AlertDialog_Sphinx">
    <item name="android:fullDark">@color/colorPrimary</item>
    <item name="android:topDark">@color/colorPrimary</item>
    <item name="android:centerDark">@color/colorPrimary</item>
    <item name="android:bottomDark">@color/colorPrimary</item>
    <item name="android:fullBright">@color/colorPrimary</item>
    <item name="android:topBright">@color/colorPrimary</item>
    <item name="android:centerBright">@color/colorPrimary</item>
    <item name="android:bottomBright">@color/colorPrimary</item>
    <item name="android:bottomMedium">@color/colorPrimary</item>
    <item name="android:centerMedium">@color/colorPrimary</item>
</style>

public class MyDialogFragment extends DialogFragment {

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    AlertDialog.Builder builder=new AlertDialog.Builder(getActivity(), R.style.AppCompatAlertDialogStyle).setTitle("Naslov")
            .setMessage("Poruka......................................................")
            .setIcon(android.R.drawable.ic_menu_help)
            .setPositiveButton("OK",null);
    return builder.create();
  }
}

I'm using support version of AlertDialog.(23.1.0) This way dialog look more like dialog on newer version of android(Material Design)

 compile 'com.android.support:appcompat-v7:23.1.0'
 compile 'com.android.support:design:23.1.0'

I want that header is of color/colorPrimary (orange) background. enter image description here

Raghunandan
  • 132,755
  • 26
  • 225
  • 256
Vlado Pandžić
  • 4,879
  • 8
  • 44
  • 75

3 Answers3

1

In the latest API levels the alert dialog does not have a separate header. It has a single view and a divider which separates the header text and message. You can change the header text and message text colors and also the divider colour. Also, you can change the background of the entire alert dialog but not just the header section of it.

As a workaround what you can do is: Dont set header text but use an image with text in it followed by the message. This way the divider will vanish and the image will look like the header. Basically a custom alert dialog.

Check this post to see how to add an image in alertdialogs.

Community
  • 1
  • 1
Viral Patel
  • 32,418
  • 18
  • 82
  • 110
0

You can create a custom view for the alert dialog.

LayoutInflater inflater = getLayoutInflater();
View dialoglayout = inflater.inflate(R.layout.dialog_layout, (ViewGroup) getCurrentFocus());
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(dialoglayout);
builder.show();
Febi M Felix
  • 2,799
  • 1
  • 10
  • 13
0

You can check out this material dialogs library here. It is very easy to use and also very customizable.

Bobby
  • 1,416
  • 1
  • 17
  • 30
  • I'll try not to use any libraries just because of design. But my web page has this kind of dialogs where header is orange, and body and footer is white. It thought it would be nice to accomplish something like that. Also, I thought it is easy to change just like on the web :) – Vlado Pandžić Jan 06 '16 at 12:29
  • I will not try for now, but if it is easy to accomplish that with your library I would consider it as an option. – Vlado Pandžić Jan 06 '16 at 12:31
  • It seems there is not header background option but you put advertisment here which is good for you library. – Vlado Pandžić Jan 06 '16 at 13:37
  • This is not my library, but look at the custom themed dialog you can make, it may help somewhat. If you are not using 3rd party libraries, that's okay too. – Bobby Jan 07 '16 at 01:05