点击它后,我找不到任何有关更改背景颜色的信息,并使用点击的颜色更改所有活动/片段的背景。
我暂时拥有该模型:
public static ColorHandler getInstanceColor(){
return mInstanceColor;
}
public ColorHandler(Context context){
mInstanceColor=this;
colorPreferences = context.getSharedPreferences(mypreference, Context.MODE_PRIVATE);
if (colorPreferences.contains("colorPref")){
currentColor = (String) colorPreferences.getAll().get("colorPref");
}
else{
currentColor = Red;
}
}
public String getColor(){
return currentColor;
}
public void setColor(String colory){
//currentColor= colory;
SharedPreferences.Editor editor = colorPreferences.edit();
editor.clear();
editor.putString("colorPref",colory);
editor.commit();
对于控制器:
private ListView listColor;
private String[] mStrings = {"BlueLight", "BlueDark", "GreenLigth", "GreenDark", "OrangeLigth", "OrangeDark","PinkLigth","PinkDark","GrayLigth","GrayDark","RedLigth","RedDark","HiddenLigth","HiddenDark"};
private ColorHandler choiceColor;
choiceColor = new ColorHandler(getActivity());
listColor.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
String colory = (String) (listColor.getItemAtPosition(i));
choiceColor.setColor(colory);
String colorDesigned = (String)ColorHandler.getInstanceColor().getColor();
LinearLayout ll;
ll = (LinearLayout) getView().findViewById(R.id.mon_layout);
ll.setBackgroundColor(Color.parseColor());
Toast.makeText(getActivity(), ColorHandler.getInstanceColor().getColor(),Toast.LENGTH_LONG).show();
}
});
我想在colors.xml中用这些颜色改变背景:
<color name="BlueLight">#5C9EED</color>
<color name="BlueDark">#4A8CDB</color>
<color name="GreenLigth">#42CC6F</color>
<color name="GreenDark">#3BB75D</color>
<color name="OrangeLigth">#FAB154</color>
<color name="OrangeDark">#F49B42</color>
<color name="PinkLigth">#EC87C0</color>
<color name="PinkDark">#D770AD</color>
<color name="GrayLigth">#606873</color>
<color name="GrayDark">#3E464F</color>
<color name="RedLigth">#ED5F55</color>
<color name="RedDark">#D84C43</color>
<color name="HiddenLigth">#A5ADB8</color>
<color name="HiddenDark">#838992</color>
感谢您的帮助
答案 0 :(得分:0)
我认为您错过了以下一行中的颜色字符串
ll.setBackgroundColor(Color.parseColor());
您需要将选定的颜色字符串放在parseColor中。因此,请尝试使用以下
替换该行ll.setBackgroundColor(Color.parseColor(colorDesigned ));