【问题标题】:How to set default edittext color in android 4.x如何在 android 4.x 中设置默认的编辑文本颜色
【发布时间】:2016-07-19 01:54:39
【问题描述】:

为了设置默认主题,我在清单文件的应用程序标签中设置了它。

<application
    android:name=".App"
    android:icon="@drawable/icon"
    android:label="@string/app_name"
    android:theme="@style/AppTheme">

这是 styles.xml 中的“AppTheme”。

<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
    <item name="android:textColor">#0400ff</item>
    <item name="android:editTextColor">#ff0000</item>
</style>

这适用于 Android 5.0 和 6.0 设备。 但在 Android 4.x 中,奇怪的是它只适用于“textColor”而不是“editTextColor”。虽然我设置了这个主题,但在 android 4.x 中默认的 editText 颜色是白色的。 我不知道为什么会出现这个问题。 请给我一些提示!

【问题讨论】:

  • 我记得当我使用 AppCompatActivity 而不是 FragmentActivity 来使用 ToolBar 时发生了这种情况。

标签: android android-edittext themes


【解决方案1】:

我自己回答这个问题。我发现了一个类似的问题。 Android set edit text style globally in theme doesn't work

它告诉我应该这样使用

<item name="editTextColor">#ff0000</item>

而不是

<item name="android:editTextColor">#ff0000</item>.

我使用它是因为Android Studio自动完成功能推荐它。

现在我知道我必须同时使用这两个!

Android 5.0 和 6.0 遵循颜色 name="android:editTextColor",但 Android 4.X 遵循颜色 name="editTextColor"。

问题解决了!

【讨论】:

    【解决方案2】:

    尝试以下方法:

    Java

    Et.setTextColor()
    

    XML

    textColor="@color/yourColor"
    

    【讨论】:

    • 我询问了当我没有像您的回答那样在 EditText 中设置任何文本颜色时的情况。我想在 EditText 中设置 DEFAULT 文本颜色。
    猜你喜欢
    • 1970-01-01
    • 2021-05-24
    • 1970-01-01
    • 2017-07-28
    • 2022-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    相关资源
    最近更新 更多