【问题标题】:PreferenceFragment does not show up in ActivityPreferenceFragment 未显示在 Activity 中
【发布时间】:2015-12-01 10:18:08
【问题描述】:

我遵循了来自 android 开发者的指南“设置”。但是当我启动我的 SettingsActivity 时,我得到的只是 白屏。我做错了什么?

这是我的 SettingActivity.java

public class SettingsActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        getFragmentManager().beginTransaction()
                 .replace(android.R.id.content, new SettingsFragment())
                 .commit();
    }
}

这里是设置片段

public class SettingsFragment extends PreferenceFragment {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.preferences);
    }
}

这是首选项文件

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
    <EditTextPreference android:title="Your Name"
        android:key="username"
        android:summary="Please provide your username"></EditTextPreference>
    <CheckBoxPreference android:title="Application Updates"
        android:defaultValue="false"
        android:summary="This option if selected will allow the application to check for latest versions."
        android:key="applicationUpdates" />
    <ListPreference     android:title="Download Details"
        android:summary="Select the kind of data that you would like to download"
        android:key="downloadType"
        android:defaultValue="1"
        android:entries="@array/listArray"
        android:entryValues="@array/listValues" />
</PreferenceScreen>

这就是我切换到 SettingsActivity 的方式

Intent intent = new Intent(MainActivity.this, SettingsActivity.class);
                            startActivity(intent);

应该是白屏吗?我期待一个带有设置的默认屏幕

【问题讨论】:

    标签: android settings preferences


    【解决方案1】:

    我找到了解决方案。

    屏幕不是空白的,我的主题使所有文本在白色背景上变成白色。

    所以我刚刚为设置活动添加了一个自定义主题并将其添加到 android manifest:

            android:theme="@style/SettingsTheme"
    

    【讨论】:

    • “设置主题”在哪里?
    • 你可以随意设置,IntelliJ Amiya,我的是
    猜你喜欢
    • 2014-10-17
    • 2018-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-11
    • 1970-01-01
    • 2016-09-14
    • 1970-01-01
    相关资源
    最近更新 更多