Android-更改应用程序中所有对话框的对话框标题样式 [英] Android - change dialog title style of all dialogs in application

查看:218
本文介绍了Android-更改应用程序中所有对话框的对话框标题样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以更改Android应用程序中出现的所有警报对话框?我也想更改系统生成的对话框(就像当您长按任意一个EditText 时打开的编辑文本"对话框一样).我想更改应用程序中所有对话框的标题字体颜色和大小.

Is there a way I can change all the alert dialogs appearing in my Android application? I want to change the dialogs that are system generated as well (like the Edit Text dialog that opens up when you long tap on any EditText). I want to change the title font color and size of all the dialogs in my app.

有办法吗?

我尝试在主题中设置android:alertDialogTheme.但这似乎不起作用.以下代码-

I have tried setting android:alertDialogTheme in my theme. But it seems to be not working. Code following -

<style name="Theme.DLight" parent="android:Theme.Light.NoTitleBar">
    <item name="android:alertDialogTheme">@style/DialogStyle</item>
</style>

<style name="DialogStyle" parent="android:Theme" >    
    <item name="android:windowBackground">@drawable/background_holo_light</item>
    <item name="android:textColor">#014076</item>       
</style>

编辑

我没有从代码中调用对话框.这只是默认对话框 长时间单击任何EditText时显示.通常它 包含诸如选择单词",全选",输入"之类的键盘选项 方法等.

I'm not invoking a dialog from my code. It's just the default dialog that appears when you long click on any EditText. Generally it contains the keyboard options like Select word, Select all, Input method etc.

推荐答案

在对话框主题中,您需要修改windowTitleStyle的属性.在那里,为您的标题引用一种样式,并为此标题定义文本外观.例如,以红色和粗体显示标题:

In you dialog theme, the attribute you need to modify windowTitleStyle. There, reference a style for your title and define a text appearance for this title. For example, to display your title red and bold:

<style name="AppTheme" parent="@android:style/Theme.Holo">
    ...  
    <item name="alertDialogTheme">@style/AppTheme.AlertDialog</item>
</style>

<style name="DialogStyle" parent="@style/Theme.Holo.Dialog.Alert">    
    ...
    <item name="android:windowTitleStyle">@style/DialogWindowTitle_Custom</item>
</style>

<style name="DialogWindowTitle_Custom" parent="@style/DialogWindowTitle_Holo">
    <item name="android:maxLines">1</item>
    <item name="android:scrollHorizontally">true</item>
    <item name="android:textAppearance">@style/TextAppearance_DialogWindowTitle</item>
</style>

<style name="TextAppearance_DialogWindowTitle" parent="@android:style/TextAppearance.Holo.DialogWindowTitle">
    <item name="android:textColor">@android:color/holo_red_light</item>
    <item name="android:textStyle">bold</item>
</style>

如果您想为AlertDialog设置更多样式,我写了

If you want to style a little bit more your AlertDialog, I wrote a blog post detailing the steps.

这篇关于Android-更改应用程序中所有对话框的对话框标题样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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