Android的 - 更改自定义对话框的标题背景 [英] Android - Change custom dialog title background

查看:632
本文介绍了Android的 - 更改自定义对话框的标题背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

这篇关于Android的 - 更改自定义对话框的标题背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆