Android 上的自定义对话框:如何将其标题居中? [英] Custom dialog on Android: How can I center its title?

查看:33
本文介绍了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天全站免登陆