2015-05-06 139 views
4

我有將數據捆綁到其他活動的活動。與數據I還捆綁自定義顏色,我想在活動所示的EditText的底線2.如何以編程方式更改EditText底線

活動1具有:

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

活動2:

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

現在,當我從活動1獲取包時,是否可以通過編程方式更改EditText的顏色?如果你能幫助我,我會很感激。

回答

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