-1
有没有办法在活动和其他活动之间传递视图或按钮的颜色?我如何在活动与其他活动之间传递色彩?
“谁都会选择颜色的用户”我想了很多,我每次运行它的时候,我得到的消息:“不幸的是应用程序已经停止”!当我打开活性2
有没有办法在活动和其他活动之间传递视图或按钮的颜色?我如何在活动与其他活动之间传递色彩?
“谁都会选择颜色的用户”我想了很多,我每次运行它的时候,我得到的消息:“不幸的是应用程序已经停止”!当我打开活性2
做到这一点....
活动1
Intent pass = new Intent();
Bundle extras = new Bundle();
extras.putInt("colorResourceName", colorResourceName);
pass.putExtras(extras);
startActivity(pass);
活动2
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle data = getIntent().getExtras();
int colorResourceName = data.getIntExtra("colorResourceName", -1);
}
继Xoce的反应,如果你没有的颜色定义为资源或在某种程度上只是知道它的十六进制代码,你也可以做这样的事情:
活动1
Intent pass = new Intent();
Bundle extras = new Bundle();
extras.putInt("colorHexCode", colorHexCode); //Example of color code: "#FFFFFF"
pass.putExtras(extras);
startActivity(pass);
活动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));
}
[使用logcat的(https://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this)检查与相关的Java堆栈跟踪您的崩溃。如果您需要现有方法的帮助,请编辑您的问题以获得[mcve],并更详细地解释“视图颜色”的含义。 – CommonsWare