android - 如何更改 EditText 中的线条颜色

标签 android xml layout styles

我正在我的布局 xml 文件中创建一个 EditText

但我想将 EditText 中的颜色线从 Holo 更改为(例如)红色。 那怎么办?

enter image description here

最佳答案

这是您可以用于所有 View 的最佳工具,并且非常感谢@Jérôme Van Der Linden,它是免费的。 .

Android Holo Colors Generator 让您可以轻松创建 Android 组件,例如 EditText 或为您的 Android 应用程序使用您自己的颜色的微调器。它将生成所有必需的 9-patch 资源以及相关的 XML 可绘制对象和样式,您可以将它们直接复制到您的项目中。

http://android-holo-colors.com/

更新 1

此域似乎已过期,但该项目是开源项目,您可以在此处找到

https://github.com/jeromevdl/android-holo-colors

试试看

这张图片放在EditText

的背景中
android:background="@drawable/textfield_activated"

enter image description here


更新 2

对于 API 21 或更高版本,您可以使用 android:backgroundTint

<EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Underline color change"
        android:backgroundTint="@android:color/holo_red_light" />

更新 3 现在我们有了支持 AppCompatEditText

注意:我们需要使用 app:backgroundTint 而不是 android:backgroundTint

<android.support.v7.widget.AppCompatEditText
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:hint="Underline color change"
    app:backgroundTint="@color/blue_gray_light" />

更新 4 AndroidX版本

  <androidx.appcompat.widget.AppCompatEditText

    app:backgroundTint="@color/blue_gray_light" />

关于android - 如何更改 EditText 中的线条颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24677414/

相关文章:

android - Proguard 和 Android 适配器

java - 无法使用 EclipsePortable 为 Android 指定 targetSDKVersion

android - ListView 透明度在 android 2.2 中不起作用

c# - 使用 XmlSerializer 读取 XML 文件后,我的所有 IsDirty 标志都设置为 true

android - 如何让点击事件传递给android中的容器?

java - 如何使组件尊重列和行权重?

android - Firebase 存储 java.util.concurrent.RejectedExecutionException

java - GreenDao是否更新tableDao的数据库 session ,通过执行sql更新表记录

xml - 是否可以在 Microsoft 文档中存储自定义数据?

ajax - 使用 servlet 过滤器中的请求参数将 JSF ajax 请求重定向到 URL