在Android自定义对话框:我如何中心的称号? [英] Custom dialog on Android: How can I center its title?

查看:114
本文介绍了在Android自定义对话框:我如何中心的称号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个Android应用程序。

I'm developing an Android application.

我怎样才能使标题居中的,我使用自定义对话框?

How can I center the title for a custom dialog that I'm using?

感谢。

推荐答案

刚刚发现这个职位,而试图找出如何做同样的事情。以下是我这样做是为了其他任何人认为这在未来。

Just found this post while trying to figure out how to do the same thing. Here's how I did it for anyone else that finds this in the future.

XML样式如下:

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <style name="PauseDialog" parent="@android:style/Theme.Dialog">
            <item name="android:windowTitleStyle">@style/PauseDialogTitle</item>
        </style>

        <style name="PauseDialogTitle" parent="@android:style/TextAppearance.DialogWindowTitle">
            <item name="android:gravity">center_horizontal</item>
        </style>
        <style name="DialogWindowTitle">
        <item name="android:maxLines">1</item>
        <item name="android:scrollHorizontally">true</item>
        <item name="android:textAppearance">@android:style/TextAppearance.DialogWindowTitle</item>
        </style>
    </resources>

和我的活动onCreateDialog方法,我想我的风格创建这样的对话框对话框:

And in my activities onCreateDialog method for the dialog I want styled I create the dialog like this:

Dialog pauseDialog = new Dialog(this, R.style.PauseDialog);
pauseDialog.setTitle(R.string.pause_menu_label);
pauseDialog.setContentView(R.layout.pause_menu);

这篇关于在Android自定义对话框:我如何中心的称号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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