- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我根据示例 here 通过扩展 PreferencesActivity 创建了一个 Preferences 屏幕.
第一个屏幕显示正常,但当我点击查看第二个屏幕时,我看到它们一个叠一个。因此,根据其他一些线程的建议,我将第二个 fragment 的背景更改为黑色。
虽然我再也看不到它们了,但它仍然有效。但是我只看到第一个,除了标题。
第一个屏幕是这样的:
第二个看起来像这样:
只有标题行发生了变化,其余的保持不变。
这是我 Activity 中的代码:
public class SettingsActivity extends PreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the preferences from an XML resource
getFragmentManager().beginTransaction().replace(android.R.id.content, new PreferencesMain()).commit();
}
/**
* This fragment contains a second-level set of preference that you
* can get to by tapping an item in the first preferences fragment.
*/
public static class PreferencesMain extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.preferences);
}
@Override
public void onStart() {
super.onStart();
View view = getView();
view.setBackgroundColor(ResourcesCompat.getColor(getResources(),android.R.color.black, null));
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
view.setBackgroundColor(ResourcesCompat.getColor(getResources(),android.R.color.black, null));
}
}
/**
* This fragment contains a second-level set of preference that you
* can get to by tapping an item in the first preferences fragment.
*/
public static class PreferencesNotifications extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.preferences_notifications);
}
@Override
public void onStart() {
super.onStart();
View view = getView();
view.setBackgroundColor(ResourcesCompat.getColor(getResources(),android.R.color.black, null));
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
view.setBackgroundColor(ResourcesCompat.getColor(getResources(),android.R.color.black, null));
}
}
@Override
protected boolean isValidFragment (String fragmentName) {
return true;
}
}
首选项.xml
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:title="@string/settings_notifications">
<!-- This PreferenceScreen tag sends the user to a new fragment of
preferences. If running in a large screen, they can be embedded
inside of the overall preferences UI. -->
<PreferenceScreen
android:fragment="activities.SettingsActivity$PreferencesNotifications"
android:title="@string/settings_notifications_managePushTitle"
android:summary="@string/settings_notifications_managePushSummary">
android:background="@android:color/black"
<!-- Arbitrary key/value pairs can be included for fragment arguments -->
<extra android:name="someKey" android:value="somePrefValue" />
</PreferenceScreen>
</PreferenceCategory>
preferences_notifications.xml
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:title="@string/settings_notifications_managePushHeader">
<CheckBoxPreference
android:key="checkbox_preference"
android:title="@string/settings_notifications_managePushEntry1Title"
android:summary="@string/settings_notifications_managePushEntry1Summary" />
</PreferenceCategory>
最佳答案
添加一个header.xml
来管理设置,并使用onBuildHeaders
方法。
资源headers.xml:
<preference-headers xmlns:android="http://schemas.android.com/apk/res/android">
<header android:title="Digle"
android:fragment="activities.SettingsActivity$PreferencesMain"/>
</preference-headers>
类SettingsActivity:
public class SettingsActivity extends PreferenceActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Remove all code in here
}
@Override
public void onBuildHeaders(List<Header> target) {
super.onBuildHeaders(target);
loadHeadersFromResource(R.xml.headers, target);
}
...
}
编辑:另一种方法是使用 subscreens .您必须将 Preference
对象组放在 PreferenceScreen
中。
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:key="Settings"
android:title="@string/app_name">
<PreferenceCategory
android:title="@string/settings_notifications">
<PreferenceScreen
android:background="@android:color/black"
android:summary="@string/settings_notifications_managePushSummary"
android:title="@string/settings_notifications_managePushTitle">
<PreferenceCategory
android:title="@string/settings_notifications_managePushHeader">
<CheckBoxPreference
android:key="checkbox_preference"
android:summary="@string/settings_notifications_managePushEntry1Summary"
android:title="@string/settings_notifications_managePushEntry1Title"/>
</PreferenceCategory>
</PreferenceScreen>
</PreferenceCategory>
</PreferenceScreen>
关于显示上一个 fragment 的 Android PreferencesActivity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36742872/
我对我的 preferences.xml 文件进行了一些编辑,没有在 Eclipse 中生成任何语法标志,现在我在尝试扩展我的 PreferencesActivity 时遇到以下奇怪的错误: E/An
我根据示例 here 通过扩展 PreferencesActivity 创建了一个 Preferences 屏幕. 第一个屏幕显示正常,但当我点击查看第二个屏幕时,我看到它们一个叠一个。因此,根据其他
这个问题在这里已经有了答案: 关闭 10 年前。 Possible Duplicate: Change icons of checked and unchecked for Checkbox for
当我单击“设置”页面时,我的 CheckBoxPreference 准确地显示了我在此阶段想要的效果,但是当我选择它时,状态不会更改(即从“未选中”变为“已选中”)。 它似乎保留了 false 值(默
我想确定用户是否处于设置状态。我有一个 PreferencesActivity 和一个 SettingsFragment。 第一种方法是使用 PreferencesActivity 的 onResum
我是一名优秀的程序员,十分优秀!