我在我的布局xml文件中创建一个EditText
但我想改变颜色线在EditText从Holo(例如)红色。 怎样才能做到呢?
我在我的布局xml文件中创建一个EditText
但我想改变颜色线在EditText从Holo(例如)红色。 怎样才能做到呢?
当前回答
这是最好的工具,你可以使用所有的观点,它的免费许多感谢@Jérôme Van Der Linden。
Android Holo颜色生成器允许您轻松地创建Android组件,如EditText或旋转与您自己的Android应用程序的颜色。它将生成所有必要的9个补丁资产加上相关的XML绘图和样式,您可以直接复制到您的项目。
http://android-holo-colors.com/
更新1
这个域名似乎过期了,但是这个项目是开源的,你可以在这里找到
https://github.com/jeromevdl/android-holo-colors
试一试
这张图片放在EditText的背景
android:background="@drawable/textfield_activated"
更新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" />
其他回答
尝试下面的方法,它将转换EditText的底线颜色,当用作背景属性时。
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:left="@dimen/spacing_neg"
android:right="@dimen/spacing_neg"
android:top="@dimen/spacing_neg">
<shape>
<solid android:color="@android:color/transparent" />
<stroke
android:width="@dimen/spacing_1"
android:color="@android:color/black" />
</shape>
</item>
</layer-list>
使用这个方法..并根据视图名称修改它。这段代码工作得很好。
private boolean validateMobilenumber() {
if (mobilenumber.getText().toString().trim().isEmpty() || mobilenumber.getText().toString().length() < 10) {
input_layout_mobilenumber.setErrorEnabled(true);
input_layout_mobilenumber.setError(getString(R.string.err_msg_mobilenumber));
// requestFocus(mobilenumber);
return false;
} else {
input_layout_mobilenumber.setError(null);
input_layout_mobilenumber.setErrorEnabled(false);
mobilenumber.setBackground(mobilenumber.getBackground().getConstantState().newDrawable());
}
我不喜欢之前的答案。最好的解决方案是使用:
<android.support.v7.widget.AppCompatEditText
app:backgroundTint="@color/blue_gray_light" />
android:backgroundTint for EditText仅适用于API21+。因此,我们必须使用支持库和AppCompatEditText。
注意:我们必须使用app:backgroundTint而不是android:backgroundTint
AndroidX版本
<androidx.appcompat.widget.AppCompatEditText
app:backgroundTint="@color/blue_gray_light" />
你可以通过着色背景来改变颜色 < EditText android: backgroundTint = " @color /红" / >
这是最好的工具,你可以使用所有的观点,它的免费许多感谢@Jérôme Van Der Linden。
Android Holo颜色生成器允许您轻松地创建Android组件,如EditText或旋转与您自己的Android应用程序的颜色。它将生成所有必要的9个补丁资产加上相关的XML绘图和样式,您可以直接复制到您的项目。
http://android-holo-colors.com/
更新1
这个域名似乎过期了,但是这个项目是开源的,你可以在这里找到
https://github.com/jeromevdl/android-holo-colors
试一试
这张图片放在EditText的背景
android:background="@drawable/textfield_activated"
更新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" />