如何在 android 4.x 中设置默认编辑文本颜色

How to set default edittext color in android 4.x

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

<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'。虽然我设置了这个主题,但默认的 editText 颜色在 android 4.x 中是白色的。 我不知道为什么会出现这个问题。 请给我一些提示!

尝试以下操作:

Java

Et.setTextColor()

XML

textColor="@color/yourColor"

我自己回答。我发现了一个类似的问题。 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 遵循颜色 名字="editTextColor".

问题已解决!