[英]How do I change the background color of an activity from another activity?
I have MainActivty
and SettingsActivity
, when I press a button in my SettingsActivity
I want the background color of the MainActivity
to change. 我有
MainActivty
和SettingsActivity
,当我在SettingsActivity
按下按钮时,我希望MainActivity
的背景色发生变化。
How do I achieve this? 我该如何实现? Sorry if this question is a bit dumb, I recently started out and I'm a bit lost.
抱歉,这个问题有点愚蠢,我最近刚开始,有点迷路。
Save the color Hex as String or Integer of Color to SharedPreferences and get it on activity @onCreate() 将颜色十六进制作为字符串或颜色整数保存到SharedPreferences,并在活动@onCreate()上获取它
SharedPreferences preferences= context.getSharedPreferences(
"SharedPrefName", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putString("SharedPrefKey","#FF0000" /*change this to what you want*/);
editor.apply();
then in activity get color 然后在活动中变色
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
String color = preferences.getString("SharedPrefKey", "#000000");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.