How to programmatically change the right line of an EditText

I have an activity in which I associate data with another activity. With this data, I will also associate a custom color that I would like to have on the bottom line of the EditText shown in step 2.

Action 1:

Bundle bundle = new Bundle();
bundle.putExtra("Color", color);

Action 2:

int value = getIntent().getExtras().getInt(Color)

Now, can I change the color of the EditText programmatically when I receive the package from activity 1? If you can help me, I would be very grateful.

+4
source share
2 answers

Maybe something like

Action 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);

Try this and let me know if it works or not.

+6
source

Action 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();

Action 2

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

All Articles