【问题标题】:Change color of EditText android更改 EditText android 的颜色
【发布时间】:2015-11-09 12:40:50
【问题描述】:

我在深色背景上有一个 EditText。 我的 EditTexts 只有黑色(如果没有聚焦),所以不正确可见。 我怎样才能改变颜色? 下面是截图。

【问题讨论】:

  • 像这样设计一个图像文件并将其设置为textview的bottomdrawable

标签: android android-layout android-edittext android-styles


【解决方案1】:

你的问题是关于 Android 主题的东西。也许你应该设置你的主题的 colorControlNormal 值。就像下面这样:

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

参考here

【讨论】:

    【解决方案2】:

    试试这个,

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

    【讨论】:

    • 不,整个矩形变白了
    • 那么,你需要改变线条的颜色吗?我说的对吗?
    【解决方案3】:

    您是否在使用 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>
    

    【讨论】:

      【解决方案4】:

      试试这个可能对你有帮助

            <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>
      

      添加这个你的drawable

       <?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>
      

      它对我有用

      它可能对你有帮助。祝你好运

      【讨论】:

        【解决方案5】:

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

        API >= 21:

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

        API

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

        【讨论】:

          【解决方案6】:

          或者试试:

          android:backgroundTint:”@color/colorWhite”
          

          【讨论】:

            猜你喜欢
            • 2014-11-08
            • 2014-10-07
            • 1970-01-01
            • 2016-11-29
            • 1970-01-01
            • 1970-01-01
            • 2017-11-25
            • 2013-09-12
            • 1970-01-01
            相关资源
            最近更新 更多