Android的共享preferences mColorPicker问题 [英] Android shared preferences mColorPicker Issue

查看:151
本文介绍了Android的共享preferences mColorPicker问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用mColorPicker并运行它好,它改变了拾取颜色,但我试图获取共享preferences来获得新的颜色,所以我可以用它。
到目前为止,这个没有运气,它不会改变颜色,但只保留默认颜色。
我有preferences在一个单独的文件和主要活动是我想从获得preferences。
继承人什么我在主要活动

I am trying to use the mColorPicker and have it running good, it changes the color in the picker but I am trying to get the shared preferences to get the new color so I can use it. So far no luck with this, it doesn't change the color but keeps the default color only. I have the preferences in a separate file and in the main activity is where I want to get the preferences from. Heres what I have in the main activity

public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
     this._blimp.setTopNameColor(prefs.getInt(TOPNAME_COLOR_CHOICE, 0xffffffff));
}

当我使用日志为了这个,我得到这个-1,为0xffffffff是默认的颜色,但它并没有在这里所有的改变。
所以我知道我在这里失去了一些东西,在我有这样的设置

when I use the log for this I get a -1 for this, 0xffffffff is the default color but it doesn't change here at all. So I know I am missing something here, in the settings I have this

@Override
public boolean onPreferenceClick(Preference preference) {

  final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(LiveWallpaperSettings.this);

    final ColorPickerDialog d = new ColorPickerDialog(this, prefs.getInt("top_name_color", 0xffffffff));
    d.setAlphaSliderVisible(true);

    d.setButton("Ok", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {

            SharedPreferences.Editor editor = prefs.edit();
            editor.putInt("top_name_color", d.getColor());
            editor.commit();

        }
    });

    d.setButton2("Cancel", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {

        }
    });

    d.show();
    return true;
 }

这是我从Main.java在mColorPicker了,并把它放在我livewallpapersettings文件,而不是。在这里它改变了对话窗口的颜色没有问题,但不能在共享preference在我的主要活动文件。
这是一个梦幻般的颜色选择器,如果我可以得到它的主要活动工作,并更新的共享preferences因此它实际上改变了我的颜色。
我知道这可能是简单的东西,但希望有人能帮助我在这里。
提前致谢。
山姆

Which I took from the Main.java in the mColorPicker and put it in my livewallpapersettings file instead. In here it changes the dialog window color no problem but not in the shared preference in my main activity file. This is a fantastic color picker if I can just get it to work and update in the shared preferences in the main activity so it actually changes my color. I know it's probably something simple but hopefully someone can help me out here. Thanks in advance. Sam

推荐答案

我用的的颜色拾取和它的伟大工程。

I have used this ColorPicker and it works great.

有在preferences一个按钮来显示对话框时pressed。

Have a button in your preferences to show the dialog when pressed.

我用

SharedPreferences sharedPreferences = getSharedPreferences(MY_PREFERENCES, Activity.MODE_PRIVATE);
editor = sharedPreferences.edit();

,然后当用户选择颜色

and then when the user choose the color

editor.putInt(TEXT_COLOR, color);
editor.commit();

在您的主要活动您将通过

In your main activity you will get the color by

prefs = getSharedPreferences(Preferences.MY_PREFERENCES, Activity.MODE_PRIVATE);
textColor = prefs.getInt(Preferences.TEXT_COLOR, R.color.black);

希望这有助于。

这篇关于Android的共享preferences mColorPicker问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆