如何更改 EditText 中的线条颜色 [英] How to change line color in EditText

查看:22
本文介绍了如何更改 EditText 中的线条颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am creating an EditText in my layout xml file

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

But I want to change color line in EditText from Holo to (for example) red. How that can be done?

推荐答案

这是最好的工具,您可以使用它来处理所有视图,而且非常感谢@Jérôme Van Der Linden.

This is the best tool that you can use for all views and its FREE many thanks to @Jérôme Van Der Linden.

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

The Android Holo Colors Generator allows you to easily create Android components such as EditText or spinner with your own colours for your Android application. It will generate all necessary nine patch assets plus associated XML drawable and styles which you can copy straight into your project.

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

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

更新 1

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

This domain seems expired but the project is an open source you can find here

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

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

试试

这张图片放在EditText

android:background="@drawable/textfield_activated"

更新 2

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

For API 21 or higher, you can use 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

Note: We need to use app:backgroundTint instead of 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" />

更新 4AndroidX 版本

Update 4 AndroidX version

  <androidx.appcompat.widget.AppCompatEditText

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

这篇关于如何更改 EditText 中的线条颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆