gpt4 book ai didi

Android:PreferenceFragment 只显示第一偏好

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:35:36 28 4
gpt4 key购买 nike

我在 Android 中加载 PreferenceFragment 时遇到问题。在这一点上,它是一个非常基本的实现,我想稍后在它工作时对其进行扩展。

问题是导航到 SettingsFragment 后只显示第一个首选项。

我没有收到任何错误,但 logcat 向我显示了这个:

W/PathParser:点相距太远 4.000000596046461

我用谷歌搜索了这个,但没有任何有用的解决方案。

代码如下:

通过NavigationDrawer导航MainActivity

navigate() 是一个使用 FragmentManager

的通用函数
case R.id.nav_settings:
navigate(new SettingsFragment(), "settingsFragment", false);
break;

设置 fragment

public class SettingsFragment extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
public SettingsFragment() { }

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

@Override
public void onResume() {
super.onResume();
getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
}

@Override
public void onPause() {
super.onPause();
getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
}

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) { }
}

prefences.xml

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">

<SwitchPreference
android:key="switch_notifications"
android:title="Notifications"
android:summary="Receive notifications"
android:defaultValue="true" >

</SwitchPreference>

<CheckBoxPreference
android:key="switch_notifications2"
android:title="Notifications"
android:summary="Receive notifications"
android:defaultValue="true" >

</CheckBoxPreference>

</PreferenceScreen>

截图

左:实际输出 |右:预览

Actual output Preview

提前致谢!

尼尔斯

最佳答案

找到解决方案:

包含我的 FrameLayoutNestedScrollView 应该具有设置 android:fillViewport="true"。此外,FrameLayout 应将其高度设置为 wrap_content。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/content_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="nmct.jaspernielsmichielhein.watchfriends.view.MainActivity"
tools:showIn="@layout/app_bar_main">

<android.support.design.widget.CoordinatorLayout
android:id="@+id/coordinator_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<android.support.v4.widget.NestedScrollView
android:id="@+id/frame_scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior" >

<FrameLayout
android:id="@+id/fragment_frame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior" >

</FrameLayout>

</android.support.v4.widget.NestedScrollView>

</android.support.design.widget.CoordinatorLayout>

</RelativeLayout>

关于Android:PreferenceFragment 只显示第一偏好,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41171735/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com