我在我的布局xml文件中创建一个EditText
但我想改变颜色线在EditText从Holo(例如)红色。 怎样才能做到呢?
我在我的布局xml文件中创建一个EditText
但我想改变颜色线在EditText从Holo(例如)红色。 怎样才能做到呢?
当前回答
尝试下面的方法,它将转换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>
其他回答
通过编程,您可以尝试:
editText.getBackground().mutate().setColorFilter(getResources().getColor(android.R.color.holo_red_light), PorterDuff.Mode.SRC_ATOP);
<EditText
android:id="@+id/et_password_tlay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:textColorHint="#9e9e9e"
android:backgroundTint="#000"
android:singleLine="true"
android:drawableTint="#FF4081"
android:paddingTop="25dp"
android:textColor="#000"
android:paddingBottom="5dp"
android:inputType="textPassword"/>
<View
android:id="@+id/UnderLine"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@+id/et_password_tlay"
android:layout_centerHorizontal="true"
android:background="#03f94e" />
**是视图**的一种操作
您可以通过编程方式更改EditText的颜色,只需使用以下代码行:
它非常简单(要求:最低API 21)…
转到xml并选择EditText字段 在右侧,你可以看到“Attributes”窗口。选择“查看所有属性” 只要搜索“tint” 添加/更改backgroundTint为所需的十六进制颜色(例如#FF0000)
保持编码……:)
线条的颜色由EditText的background属性定义。要改变它,你应该改变布局文件中的android:background。
我应该注意的是,这种风格是通过使用9个补丁绘制来实现的。如果你查看SDK,你可以看到EditText的背景是这样的图片:
要改变它,你可以在图像处理程序中打开它,并将其涂成所需的颜色。保存为bg_edit_text.9.png,然后把它放在你的可绘制文件夹。现在你可以像这样应用它作为你的EditText的背景:
android:background="@drawable/bg_edit_text"