Android的 - 更改自定义对话框的标题背景自定义、对话框、背景、标题

2023-09-05 03:45:19 作者:人心太拥挤

我创建一个自定义对话框,我想知道如何更改标题栏的背景。

I am creating a custom dialog and I want to know how to change the background of the title bar.

我已经试过两种方法:

1 - 我已经试过了AlertDialog.Builder法setCustomTitle。我创建了一个简单的布局来看,包括与布局的宽度和高度match_parent和背景颜色一个TextView的。当我运行的应用程序,标题栏只有上半部分显示的背景颜色。下半部分仍然显示的默认主题的背景色。没有人知道为什么?

1 - I've tried the AlertDialog.Builder method 'setCustomTitle'. I created a simple layout view comprising of a textview with layout width and height 'match_parent' and background color. When I run the app, only the top half of the title bar is showing the background color. The bottom half is still showing the default theme background color. Does anyone know why?

2 - 我已经创建了自己的对话主题。香港专业教育学院创建与父母继承的样式为@android:风格/ Theme.Holo.Light.Dialog。然后,我通过了,在AlertDialog.Builder构造 - 新AlertDialog.Builder(这一点,R.style.test_dialog)。这似乎不错,但不知何故被包裹在对话中的对话。一个正方形框周围的对话框。 没有人知道为什么?

2 - I've created my own dialog theme. Ive created a style with parent inheritance to '@android:style/Theme.Holo.Light.Dialog'. I've then passed that in the AlertDialog.Builder constructor - new AlertDialog.Builder(this, R.style.test_dialog). It seems good but somehow the dialog is wrapped within a dialog. A square box is surrounding the dialog. Does anyone know why?

推荐答案

您可以创建一个样式一样,

You can create a style like,

<style name="cust_dialog" parent="@android:style/Theme.Dialog">
    <item name="android:windowTitleStyle">@style/dialog_title_style</item>
  </style>

<style name="dialog_title_style" parent="android:Widget.TextView">
    <item name="android:background">@android:color/black</item>
    <item name="android:padding">10dp</item>
</style>

和可以实例对话框:

Dialog dialog=new Dialog(this,R.style.cust_dialog);
dialog.setContentView(R.layout.fragment_features_dialog);
dialog.setTitle(R.string.features);

现在的对话框显示了黑色的标题背景颜色。

Now the dialog shows up with black title background color.

 
精彩推荐
图片推荐