Android支持警报对话框更改标题背景颜色?

Android支持警报对话框更改标题背景颜色?,android,android-fragments,android-dialogfragment,android-styles,Android,Android Fragments,Android Dialogfragment,Android Styles,color/colorPrimary是我想要的橙色。但我成功地改变了标题文本的颜色,这很容易。我想改变标题背景的颜色。这就是我到目前为止所做的: <style name="AppCompatAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert"> <item name="android:textColorPrimary">@color/colorPrimary</item>

color/colorPrimary
是我想要的橙色。但我成功地改变了标题文本的颜色,这很容易。我想改变标题背景的颜色。这就是我到目前为止所做的:

<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();
  }
}
我希望标题是彩色/彩色主(橙色)背景。

您可以为警报对话框创建自定义视图

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

在最新的API级别中,“警报”对话框没有单独的标题。它有一个单独的视图和分隔符,用于分隔标题文本和消息。您可以更改标题文本和消息文本的颜色,也可以更改分隔符的颜色。此外,您可以更改整个警报对话框的背景,而不仅仅是其标题部分

作为一种解决方法,您可以做的是:不要设置标题文本,而是使用一个包含文本的图像,然后是消息。这样,分割线将消失,图像将看起来像标题。 基本上是一个自定义警报对话框

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

查看如何在alertdialogs中添加图像。

您可以查看此材质对话框库。它很容易使用,也很容易定制。

我会尽量不使用任何库,因为它是设计的。但是我的网页有这样的对话框,页眉是橙色的,正文和页脚是白色的。它认为完成这样的事情会很好。此外,我认为这很容易改变,就像在网络上:“我现在不会尝试,但如果很容易做到这一点与您的图书馆,我会认为这是一个选择。似乎没有头背景选项,但你把广告在这里,这是有益的你的图书馆。这不是我的图书馆,但是看看你可以创建的自定义主题对话框,它可能会有所帮助。如果您不使用第三方库,也可以。当然有一个选项,但我认为headerBackground:#F56321是更简单的选项。但到目前为止,所有的造型选择都没有帮助。