如何定制一个对话框的标题布局 [英] How can I customize the header layout of a dialog

查看:159
本文介绍了如何定制一个对话框的标题布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Android上,是可以自定义标题布局(图标+文字)对话框的布局?或者,我可以只设置标题文本的字符串值?

In android, is it possible to customize the header layout (the icon + a text) layout of a dialog? Or I can just set the string value of the title text?

感谢您。

推荐答案

这是可能的,如果你设置对话框和标题都自定义布局改变对话框的标题。我只用过这种方法完全去除头,但是这应该自定义页眉工作:

It's possible to change the header of the Dialog if you set a custom layout for both the dialog and the header. I've only ever used this method to remove the header entirely, but this ought to work for a custom header:

dialog = new Dialog(context);
Window window = dialog.getWindow();
window.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
dialog.setContentView(R.layout.my_dialog_layout);
window.setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.my_custom_header);

这是所有的一点点更复杂(因为你必须设置对话框的布局,以及),但它比继承对话更容易。

This is all a tad more complicated (as you have to setup the dialog's layout as well) but it's easier than subclassing Dialog.

这篇关于如何定制一个对话框的标题布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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