更改 EditText 的颜色 android

Change color of EditText android

我有一个深色背景的 EditText。 我的 EditTexts 仅为黑色(如果未聚焦),因此无法正常显示。 我怎样才能改变颜色? 下面是屏幕截图。

试试这个,

 editText.getBackground().setColorFilter(getResources().getColor(R.color.white), PorterDuff.Mode.SRC_ATOP);

你的问题是关于 Android 主题 stuff.Maybe 你应该像下面这样设置你的 colorControlNormal value.Just 主题:

<style name="Theme.App.Base" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorControlNormal">#YOUR COLOR HEER</item>
</style>

引用here.

您使用的是 AppCompat 库吗?如果是,您可以覆盖样式属性 colorControlNormalcolorControlActivatedcolorControlHighlight.

例如:

<style name="Theme.App.Base" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorControlNormal">@color/your_color_1</item>
    <item name="colorControlActivated">@color/your_color_2</item>
    <item name="colorControlHighlight">@color/your_color_3</item>
</style>

试试这个可能对你有帮助

      <EditText
            android:textColorHint="@android:color/white"
            android:id="@+id/username"
            style="@style/EditUnderBar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/transparent"
            android:hint="@string/hint_email" />

将此添加到您的 style.xml

 <style name="EditUnderBar" parent="android:Widget.Holo.Light.TextView">
    <item name="android:drawableBottom">@drawable/under_bar</item>
    <item name="android:drawablePadding">3dp</item>
    <item name="android:layout_marginTop">12dp</item>
    <item name="android:paddingLeft">4dp</item>
    <item name="android:textColor">@color/white</item>
    <item name="android:textSize">16sp</item>
</style>

将此添加到您的可绘制对象

 <?xml version="1.0" encoding="utf-8"?>
 <shape
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:shape="rectangle">
  <size android:width="1000dp" android:height="1dp" />
  <solid
     android:color="@color/white"/>
  </shape>

如果它不起作用,那么也添加这个

  <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->

    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="android:textColorPrimary">@color/textColorPrimary</item>
    <item name="colorControlNormal">@color/iron</item>
    <item name="colorControlActivated">@color/white</item>
    <item name="colorControlHighlight">@color/white</item>
    <item name="android:textColorHint">@color/white</item>
    <item name="colorAccent">@color/accent</item>
    <item name="android:windowBackground">@color/white</item>
</style>

对我有用

可能会有帮助you.Good运气

或尝试:

android:backgroundTint:”@color/colorWhite”

在 edittext 中更改线条颜色的最简单方法是在 xml 文件中写入:

API >= 21:

<EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:backgroundTint="YOUR COLOR" />

API < 21:

<EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:backgroundTint="YOUR COLOR" />