Is there a way to pass color of view or button between activity and another?
"the user who will Choose Color"
I tried a lot and every time I run it, I get the message:"unfortunately app has stopped"! when i open activity2
Is there a way to pass color of view or button between activity and another?
"the user who will Choose Color"
I tried a lot and every time I run it, I get the message:"unfortunately app has stopped"! when i open activity2
Do this....
Activity 1
Intent pass = new Intent( );
Bundle extras = new Bundle();
extras.putInt("colorResourceName", colorResourceName);
pass.putExtras(extras);
startActivity(pass);
Activity 2
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle data = getIntent().getExtras();
int colorResourceName = data.getIntExtra("colorResourceName", -1);
}
Following Xoce's response, you can also do something like this if you don't have the color defined as a resource or somehow just know it's hex code:
Activity 1
Intent pass = new Intent( );
Bundle extras = new Bundle();
extras.putInt("colorHexCode", colorHexCode); //Example of color code: "#FFFFFF"
pass.putExtras(extras);
startActivity(pass);
Activity 2
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle data = getIntent().getExtras();
String colorHexCode = data.getStringExtra("colorHexCode");
TextView textView = (TextView) findViewById(R.id.my_text_view);
textView.setTextColor(Color.parseColor(colorHexCode));
}