我开发一个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);