如何在最低 API 级别 14 中以编程方式更改 EditText 行颜色和 EditText 光标颜色?

4
我尝试了下面的代码片段,但在API21以下版本中它不能正常工作:
editText.getBackground().setColorFilter(editTextColor, PorterDuff.Mode.SRC_IN);
editText.getBackground().mutate().setColorFilter(editTextColor,PorterDuff.Mode.SRC_ATOP);

请告诉我如何改变API 14。

2个回答

5
请使用以下内容:
Drawable drawable = editText.getBackground();
drawable.setColorFilter(editTextColor, PorterDuff.Mode.SRC_ATOP);
if(Build.VERSION.SDK_INT > 16) {
    editText.setBackground(drawable);
}else{
    editText.setBackgroundDrawable(drawable);
}

不用谢,请接受Ronitkadwane的问题。 - Michele Lacorte

0

android:textCursorDrawable属性设置为@null应该会使用android:textColor作为光标颜色。

属性textCursorDrawable在API级别12及更高版本中可用。


这是来自 XML 而非程序化的内容。 - Ronit kadwane

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接