的preferences使用preferenceActivity时,令人耳目一新的观点耳目、观点、preferences、preferenceActivity

2023-09-06 02:22:37 作者:风信子

我试图迫使 preferenceActivity 刷新。有谁知道如何做到这一点?

I'm trying to force PreferenceActivity to refresh. Does anyone know how to do this?

我有一个 ResetDefaults preference 类的子类 preference ,并点击时,为应该重置为默认设置所有preferences,它的键启动具有一定的preFIX。它的工作原理,但是当我打的复位preference,没有preferences在屏幕更新,直到我回来了屏幕和返回。(这适用于一些自定义颜色preferences,但对于那些我必须得离开,重新进入 preferenceActivity < - 即使是不适合某些目录preference 工作/ code>本身要显示的更新后的值。)

I have a ResetDefaultsPreference class that subclasses Preference and, when clicked, is supposed to reset to defaults all preferences whose keys start with a certain prefix. It works, but when I hit the reset preference, none of the preferences in that screen update until I back out of the screen and go back in. (That works for some custom color preferences, but even that doesn't work for some ListPreferences - for those I have to leave and re-enter the PreferenceActivity itself for the updated values to be shown.)

我试图通过获取根视图和无效()荷兰国际集团它来解决这个问题,但似乎并没有工作。下面是该行刷新显示。这是在 preference 子类,它保持了上下文它 mContext

I tried to fix this by getting the root view and invalidate()ing it, but that doesn't seem to work. Here's the line to refresh the display. It's in part of a Preference subclass that keeps the Context it was created with in mContext.

((Activity)mContext).findViewById(android.R.id.content).invalidate();

这发生在preference值被修改并提交后。 (该值的变化,但显示没有。)有谁知道我怎么能强迫preferenceActivity刷新自己?

This happens after the preference values have been changed and committed. (The values change, but the display doesn't.) Does anyone know how I can force PreferenceActivity to refresh itself?

推荐答案

我不知道的方式,以刷新preferenceActivity,但可以造成一种错觉给用户。它将将关闭并重新打开活动,没有动画,所以它会出现,如果该值只是改变。

I don't know of a way to "refresh" the PreferenceActivity, but you can create the illusion to the user. It will will close and reopen the activity with no animations, so it will appear as if the value just changes.

Intent intent = getIntent();
overridePendingTransition(0, 0);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
finish();
overridePendingTransition(0, 0);
startActivity(intent);