我尝试将PreferenceFragmentCompat加载到FrameLayout。但是当我尝试用SettingsFragment替换片段时,应用程序就会死掉。我从Logcat得到的一切都是:"发送信号。 PID:16947 SIG:9"
如何将SettingsFragment放置到FrameLayout?
public class SettingsFragment extends PreferenceFragmentCompat {
@Override
public void onCreatePreferences(Bundle bundle, String s) {
setPreferencesFromResource(R.xml.fragment_settings, s);
}
}
fragment_settings.xml:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent">
<PreferenceCategory
android:title="HTTP Requests">
<PreferenceCategory
android:title="Zustand abfragen">
<EditTextPreference
android:key="state_request_url"
android:title="URL"
android:summary="Test"
android:dialogTitle="Test" />
</PreferenceCategory>
<PreferenceCategory
android:title="Zustand ändern">
<EditTextPreference
android:key="state_change_url"
android:title="URL"
android:summary="Test"
android:dialogTitle="Test" />
</PreferenceCategory>
</PreferenceCategory>
</PreferenceScreen>
我如何加载片段:
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.fragment_container, new SettingsFragment());
transaction.addToBackStack(null);
transaction.commit();
错误:
04-11 22:34:11.862 11083-11083/? I/art: Late-enabling -Xcheck:jni
04-11 22:34:11.862 11083-11083/? I/art: Reinit property: dalvik.vm.checkjni= false
04-11 22:34:11.951 11083-11083/? W/System: ClassLoader referenced unknown path: /data/app/de.home.smarthome-2/lib/arm64
04-11 22:34:11.952 11083-11083/? W/art: JIT profile information will not be recorded: profile file does not exits.
04-11 22:34:11.957 11083-11083/? I/InstantRun: Starting Instant Run Server for de.home.smarthome
04-11 22:34:12.188 11083-11090/? I/art: Debugger is no longer active
04-11 22:34:12.188 11083-11090/? I/art: Starting a blocking GC Instrumentation
04-11 22:34:12.252 11083-11083/? I/HwCust: Constructor found for class android.app.HwCustActivityImpl
04-11 22:34:12.271 11083-11083/? I/HwCust: Constructor found for class android.app.HwCustHwWallpaperManagerImpl
04-11 22:34:12.295 11083-11083/? W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
04-11 22:34:12.436 11083-11083/? I/HwSecImmHelper: mSecurityInputMethodService is null
04-11 22:34:12.442 11083-11083/? I/HwPointEventFilter: support AFT
04-11 22:34:12.474 11083-11176/? I/OpenGLRenderer: Initialized EGL, version 1.4
04-11 22:34:12.483 11083-11176/? W/linker: /vendor/lib64/libhwuibp.so: unused DT entry: type 0xf arg 0xe3a
04-11 22:34:12.635 11083-11083/? W/art: Before Android 4.1, method int android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
04-11 22:34:16.695 11083-11083/de.home.smarthome I/Process: Sending signal. PID: 11083 SIG: 9