У меня есть две картинки, они кликабельные, нажимая на эти картинки, я меняю цвет Action Bar. Но один код работает отлично, другой абсолютно такой же , но немного с другими названиями не работает.
1 КОД
sharedPreferences = getSharedPreferences("ShaPreferences", Context.MODE_PRIVATE);
final SharedPreferences sharedPreferences = getSharedPreferences("ShaPreferences", Context.MODE_PRIVATE);
String hexColor = sharedPreferences.getString("toolbarColor", "");
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor(hexColor)));
pinkcolor.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String hexColor = "#eca190";
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor(hexColor)));
SharedPreferences.Editor editor=sharedPreferences.edit();
editor.putString("toolbarColor",hexColor);
editor.commit();
}
});
2 КОД
sharedPreferences1 = getSharedPreferences("ShaPreferences1", Context.MODE_PRIVATE);
final SharedPreferences sharedPreferences1 = getSharedPreferences("ShaPreferences1", Context.MODE_PRIVATE);
String hexColor1 = sharedPreferences1.getString("toolbar", "");
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor(hexColor1)));
greencolor.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String hexColor1 = "#8bc34a";
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor(hexColor1)));
SharedPreferences.Editor editor1=sharedPreferences1.edit();
editor1.putString("toolbar",hexColor1);
editor1.commit();
}
});
Ошибку выдает на:
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor(hexColor1)));
Сама ошибка:
Caused by: java.lang.StringIndexOutOfBoundsException: length=0; index=0