2

color/colorPrimary是我想要标题的一些橙色。但我成功地更改了标题文本颜色,这很容易。我想改变标题背景的颜色。这是我到目前为止有:Android支持警报对话框更改标题背景颜色?

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

我使用AlertDialog的支持版本(23.1.0)这样对话框看起来更像是新版Android对话框(材质设计)

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

我想要那个头是彩色/ colorPrimary(橙色)背景。 enter image description here

回答

0

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

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

肯定的一个选择,但我虽然headerBackground:#F56321是更简单的选项。但到目前为止,造型的所有选择都没有帮助。 –

1

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

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

检查this post以查看如何在alertdialogs中添加图像。

0

您可以查看此材质对话框库here。它使用起来非常简单,而且非常可定制。

+0

我会尽量不要因为设计而使用任何库。但是我的网页有这种类型的对话框,头部是橙色的,而主体和页脚是白色的。它认为这将是很好的完成这样的事情。此外,我认为这很容易就像在网络上一样改变:) –

+0

我现在不会尝试,但如果用你的图书馆很容易完成,我会认为它是一个选项。 –

+0

它似乎没有标题背景选项,但你把广告放在这里,这对你图书馆很好。 –