String abColor = sharedPreferences.getString("action_bar_color", "#ffffff");
String sbColor = sharedPreferences.getString("status_bar_color", "#ffffff");
ActionBar ab = getSupportActionBar();
ab.setBackgroundDrawable(new ColorDrawable(Color.parseColor(abColor)));
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(Color.parseColor(sbColor));
我一直在獲取java.lang.IllegalArgumentException:未知顏色錯誤指向變量sbColor
。儘管變量abColor
的使用方式與sbColor
相同,但它的工作原理完全正常。java.lang.IllegalArgumentException:未知顏色
請你幫我找出爲什麼Android Studio會拋出這個錯誤。
prefs = getSharedPreferences("AppPrefs", Context.MODE_PRIVATE);
String logged = prefs.getString("LOGGED", "OUT");
mRemoteConfig = FirebaseRemoteConfig.getInstance();
FirebaseRemoteConfigSettings remoteConfigSettings = new FirebaseRemoteConfigSettings.Builder()
.setDeveloperModeEnabled(true)
.build();
mRemoteConfig.setConfigSettings(remoteConfigSettings);
HashMap<String, Object> defaults = new HashMap<>();
defaults.put("action_bar_color", R.color.colorPrimary);
defaults.put("status_bar_color", R.color.colorPrimaryDark);
mRemoteConfig.setDefaults(defaults);
final Task<Void> fetch = mRemoteConfig.fetch(0);
fetch.addOnSuccessListener(this, new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
mRemoteConfig.activateFetched();
SharedPreferences.Editor editor = prefs.edit();
editor.putString("action_bar_color", mRemoteConfig.getString("action_bar_color"));
editor.putString("status_bar_color", mRemoteConfig.getString("status_bar_color"));
editor.apply();
打印sbColor的值,它可能不是你所期望的 – Les
什麼是保存在首選項'status_bar_color'鍵? –
你正在把整數,並期望讀取字符串 –