在PreferenceScreen中显示crouton

时间:2013-12-04 11:08:45

标签: android crouton

我正在使用Crouton库向用户显示警告消息。在这种情况下,我想在特定的首选项屏幕中显示。我在PreferenceActivity

中编写了以下代码

但是,Crouton仅显示在第一个“首选项”屏幕中,而不显示在实际触发了Crouton的子项首选项屏幕上。有什么想法可以解决这个问题吗?

       findPreference(key.key).setOnPreferenceChangeListener(new OnPreferenceChangeListener()
        {

            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue)
            {
                int count = 0;
                for (ANALYTICS_KEYS key : ANALYTICS_KEYS.values())
                {
                    if (appPreferences.getAnalyticProperty(key))
                    {
                        count++;

                    }
                }

                Crouton crouton = null;
                if (count > 5 && count < 7)
                {
                    Style.Builder style = new Builder(Style.INFO).setConfiguration(new Configuration.Builder().setDuration(Configuration.DURATION_INFINITE).build());

                    crouton = Crouton.makeText(DashAnalyticsPreferenceActivity.this, "More than 5 attributes might not be visible", style.build());

                }
                else if (count > 7)
                {
                    crouton = Crouton.makeText(DashAnalyticsPreferenceActivity.this, "More than 7 attributes are not allowed. Only first 7 will be considered", Style.ALERT);
                }
                else
                    Crouton.cancelAllCroutons();

                if (crouton != null)
                {
                    crouton.show();
                    crouton.setOnClickListener(new View.OnClickListener()
                    {
                        @Override
                        public void onClick(View v)
                        {

                            //Crouton.hide(crouton);
                        }
                    });
                }

                return true;
            }

1 个答案:

答案 0 :(得分:1)

Crouton附加到“激活”视图。因此,它只会显示在已创建它的Activity中。

如果您想在其他Crouton中显示Activity,则必须将相应的Activity传递给它。