【问题标题】:Changing the Title and EditText color in androidx.preference.EditTextPreference更改 androidx.preference.EditTextPreference 中的 Title 和 EditText 颜色
【发布时间】:2020-10-14 04:25:52
【问题描述】:

我发现了一些关于这个主题的类似问题,但它适用于 support version 而不适用于 androidx。我无法在 androidx 上进行此更改。但是在以前的支持版本上已经有解决方案了。谁能给我一些关于如何更改 EditTextPreference 中的标题和 editetext 字段文本颜色的指示?目前颜色为白色,背景也为白色,文字不可见。

这是我已经在 stackoverflow 上找到的解决方案,但我无法使用。我想将白色文本颜色更改为黑色。谢谢。

【问题讨论】:

  • 尝试将主题添加到您的对话框中。
  • @Yeldar.N 我试过了。我在覆盖时遇到错误:AAPT: error: resource android:style/Preference.DialogPreference.EditTextPreference is private.

标签: android androidx edittextpreference


【解决方案1】:

在 Murphybro2 的解决方案的线程中,我们也得到了 androidx 的解决方案 https://stackoverflow.com/a/58836953

您可以通过提供自定义主题样式来更改应用使用的 AlertDialogStyle

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

<style name="Theme.example.AlertTheme" parent="">
    <item name="android:textViewStyle">@style/Theme.AlertTextStyle</item>
    <item name="android:textColor">@color/pink</item>
    <item name="android:editTextBackground">@color/pink</item>
    <item name="android:windowMinWidthMajor">@dimen/abc_dialog_min_width_major</item>
    <item name="android:windowMinWidthMinor">@dimen/abc_dialog_min_width_minor</item>
    <item name="android:windowIsFloating">true</item>
</style>

<style name="Theme.AlertTextStyle" parent="Theme.example">
        <item name="android:textColorPrimary">@color/gray</item>
</style>

对我来说最重要的是 "windowIsFloating">true 因为否则窗口会卡在屏幕顶部 对我来说,不知何故,仅添加额外的 textViewStyle 有助于更改对话框内的顶部文本,但我认为这是因为我的示例主题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-19
    • 1970-01-01
    • 2014-10-07
    • 2012-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-08
    相关资源
    最近更新 更多