Android 设置EditText的背景,同时保持线条颜色

Android 设置EditText的背景,同时保持线条颜色,android,colors,android-edittext,line,background-color,Android,Colors,Android Edittext,Line,Background Color,单击“编辑”按钮时,我会使用以下命令更改EditText的外观: editText.setBackgroundColor(Color.parseColor("#E1E2E3")); editText.getBackground().setAlpha(80); 其结果是: 它删除EditText中文本下方显示的行。我已经尝试添加了editText.getBackground().setColorFilter(Color.parseColor(#DACC3E))、PorterDuff.Mode.S

单击“编辑”按钮时,我会使用以下命令更改EditText的外观:

editText.setBackgroundColor(Color.parseColor("#E1E2E3"));
editText.getBackground().setAlpha(80);
其结果是:


它删除EditText中文本下方显示的行。我已经尝试添加了
editText.getBackground().setColorFilter(Color.parseColor(#DACC3E))、PorterDuff.Mode.SRC_-in)但这只会更改背景的颜色。有没有办法在保持此背景色的同时恢复下划线?

只需将
EditText
的背景设置为一种颜色即可覆盖默认背景,即彩色下划线。您必须创建自己的文本作为您的
编辑文本的背景,而@Bryan的答案可能是官方推荐的方式。。。您可以使用一些变通方法:只需将
编辑文本
包装在
视图组
中,并将您的背景更改应用到
视图组
,而不是
编辑文本
。e、 g

<LinearLayout
    android:id="@+id/et__parent"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</LinearLayout>

或者欺骗并将编辑文本包装在视图组中,并将背景颜色更改应用于父级?@guarders啊,是的,这也会起作用(甚至更好)。我没想到,你应该把它贴出来作为答案。
findViewById(R.id.et__parent)
    .setBackgroundColor(Color.parseColor("#50E1E2E3")); // 50 = 80 in HEX