以编程方式将背景色调设置为EditText视图

Axo*_*123 0 android android-layout android-studio

我想有一个灰色的淡淡的色调中的背景EditText来看,几乎像文本总是不断强调,我需要以编程方式添加此.我试过setBackground(),setBackgroundTintList(),setBackgroundTintMode(),但没有他们中的一个似乎工作.

这是代码......

    EditText label = new EditText(this);
    label.setTextSize(4*dp);
    label.setTypeface(null,Typeface.BOLD_ITALIC);
    RelativeLayout.LayoutParams labelParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    labelParams.setMargins(80,0,0,0);
    labelParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
    labelParams.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
    label.setLayoutParams(labelParams);
    rootView.addView(label);
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

小智 10

让我们试试这个:

editText.getBackground().setColorFilter(getResources().getColor(R.color.your_color), PorterDuff.Mode.SRC_ATOP);
Run Code Online (Sandbox Code Playgroud)