Custom dialog on Android: How can I center its title?(Android 上的自定义对话框:如何将其标题居中?)
本文介绍了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 上的自定义对话框:如何将其标题居中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:Android 上的自定义对话框:如何将其标题居中?


猜你喜欢
- Xcode 7.3 中带有 UILabel 的 UIStackView 2022-01-01
- 类似于 Mail.app 的 iPad 模态视图控制器? 2022-01-01
- SetOnItemSelectedListener上的微调程序错误 2022-01-01
- 如何在 iPhone 模拟器中重置 NSUserDefaults 数据? 2022-01-01
- 使用自动布局向 UIScrollView 添加动态大小的视图 2022-01-01
- UITextView 内容插图 2022-01-01
- 网上有没有好的 UIScrollView 教程? 2022-01-01
- URL编码Swift iOS 2022-01-01
- 在 Iphone SDK 的导航栏上添加多个按钮 2022-01-01
- GPS状态的广播接收器? 2022-01-01