问题描述
我试图表现出 preferenceFragment
后,我选择在我的动作条的preferences选项。
然而,随着 preferenceFragment
替换当前的内容后,你可以看到它下面的旧内容。正如你可以看到直接通过preferences。
I'm trying to show a PreferenceFragment
after I select the Preferences option in my ActionBar.However, after replacing current content with the PreferenceFragment
you can see the old content below it. As in, you can see straight through the preferences.
我失去了一些东西在这里?我曾经从一本书我自己,它没有使用任何布局文件preferences一个例子。你需要这些?
Am I missing something here? I used an example from a book I own, which didn't use any layout files for the preferences. Do you need those?
使用code:
动作条菜单
private boolean MenuChoice(MenuItem item) {
switch (item.getItemId()) {
case 0:
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction =
fragmentManager.beginTransaction();
ReaderPreferences prefs = new ReaderPreferences();
fragmentTransaction.replace(android.R.id.content, prefs);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
return true;
}
return false;
}
preferenceReader
PreferenceReader
public class ReaderPreferences extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// --load the preferences from an XML file---
addPreferencesFromResource(R.xml.preference);
}
}
实际结果:
正如你所看到的,你通过我的preferences直视。
我做了什么错了?
As you can see, you look straight through my preferences.What did I do wrong?
推荐答案
最后一个非常简单的办法固定它。
Eventually fixed it with a very easy fix.
我简单地叫 preferenceFragment
新的意图
,和它的工作完美。
I simply called the PreferenceFragment
in a new Intent
, and it worked perfectly.
对于同样的问题,任何人:
For anyone with the same problem:
prefs.java
public class ReaderPreferences extends PreferenceActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// --load the preferences from an XML file---
addPreferencesFromResource(R.xml.preference);
}
在我的主屏幕时pressing一个按钮:
Intent i = new Intent(this, Prefs.class);
startActivity(i);
这就是全部。设置preferences后只需preSS后退按钮就大功告成了。
That's all. After setting the preferences simply press the back button and you're done.
这篇关于preferenceFragment被透明地显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!