Android EditTextPreference对话框样式/主题 [英] Android EditTextPreference dialog style/theme

查看:86
本文介绍了Android EditTextPreference对话框样式/主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置我在SettingsActivity中选择EditTextPreference时出现的对话框的样式.到目前为止,我已经能够通过以下方式更改两个按钮的颜色和背景:

I'm trying to style the dialog box that appears when I select an EditTextPreference in my SettingsActivity. So far I have been able to change the colour of the two buttons and the background with:

    dialog.getButton(DialogInterface.BUTTON_NEGATIVE).setTextColor(0xffffffff);
    dialog.getButton(DialogInterface.BUTTON_POSITIVE).setTextColor(0xffffffff);
    dialog.getWindow().setBackgroundDrawableResource(R.drawable.blue_background);

但是,到目前为止,我无法更改对话框顶部的标题.

正在从用于首选项列表的样式中检索区域"标题的颜色,它是继承的,我不知道如何为它分配一种会更改标题颜色的样式

The colour of the 'Zone' title is being retrieved from a style I use for the preference list, it's being inherited and I can't figure out how to assign it a style that will change that title colour

<style name="MyPreferenceTheme" parent="Theme.AppCompat.NoActionBar">
    <item name="android:windowBackground">@color/care_call_white</item>
    <item name="android:textColor">@drawable/text_colour_state</item>
    <item name="android:textColorSecondary">@drawable/text_colour_state</item>
</style>

任何人都可以提供可以做到这一点的样式吗?还是用一些可能会设置它的代码?我所有的对话框的样式都相同,但这是一个比较棘手的对话框,因为它是首选项"的一部分,因此我无法像使用其他对话框一样自定义它.

Can anyone help with a style that could do this? Or with some code that could possibly set it instead? All my dialog boxes are styled the same but this one is trickier as it's part of the Preference so I can't customise it the same way I did with the others.

只需澄清一下,唯一需要更改的是区域"标题.我希望它是白色的.

Just to clarify, the only thing that needs changing is the "Zone" title.. I would like it to be white.

推荐答案

有了新的AndroidX首选项库, EditTextPreference 中没有 onPrepareDialogBu​​ilder .

With new AndroidX Preference library there is no onPrepareDialogBuilder in EditTextPreference.

我已经按照这种方式进行了:

I've proceeded in this way:

我的基本应用主题:

<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
     //add here your properties
</style>

我的偏好主题:

<style name="AppTheme.Settings">
     <!-- This will change the opening dialogs for EditTextPreference -->
     <item name="alertDialogStyle">@style/Theme.AlertDialog.Default</item>
</style>

在我的情况下,

Theme.AlertDialog.Default 是一个自定义Dialog主题,其父级为 ThemeOverlay.MaterialComponents.MaterialAlertDialog

in my case Theme.AlertDialog.Default is a custom Dialog theme with with parent ThemeOverlay.MaterialComponents.MaterialAlertDialog

然后在您的 AndroidManifest.xml 中,只需将主题应用于处理首选项的Activity

Then in your AndroidManifest.xml simply apply the theme to the the Activity which handle the preferences

这篇关于Android EditTextPreference对话框样式/主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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