如何通过编程更改EditText底部的线

4
我有一个活动,在其中我将数据捆绑到另一个活动中。使用该数据,我还捆绑了一个自定义颜色,我希望在第二个活动中显示EditText的底部线条。
第1个活动:
Bundle bundle = new Bundle();
bundle.putExtra("Color", color);

活动2:
int value = getIntent().getExtras().getInt(Color)

现在,当我从第一个活动获取bundle时,我能否通过编程方式更改EditText的颜色?如果您能帮助我做到这一点,我将非常感激。
2个回答

6
可能是这样的,
活动2//
int value = getIntent().getExtras().getInt(Color);
// Here I assume you have defined edittext form layout file so it is not null
editText.getBackground().setColorFilter(value, PorterDuff.Mode.SRC_ATOP);

试一下并让我知道,它有效吗?


-1

活动 1

Intent intent = new Intent(Activity1.this, Activity2.class);
Bundle bundle  = new Bundle();
bundle.putInt("Color", color); //Your id
intent.putExtras(bundle); //Put your id to your next Intent
startActivity(intent);
finish();

活动 2

Bundle b = getIntent().getExtras();
int value = b.getInt("Color");

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