jus*_*oob 5 android sharedpreferences preferencefragment
在我的Android应用程序中,我定义了一个非常基本的PreferenceScreen:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<ListPreference
android:entries="@array/test_entries"
android:entryValues="@array/test_values"
android:key="key_test1"
android:title="Test title 1" />
<CheckBoxPreference
android:key="key_test2"
android:summary="Test description 1"
android:title="Test title 2" />
</PreferenceScreen>
Run Code Online (Sandbox Code Playgroud)
并实现了相应的PreferenceFragmentCompat类:
class SettingsFragment : PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.settings, rootKey)
}
}
Run Code Online (Sandbox Code Playgroud)
我正在使用的依赖:
implementation "com.android.support:preference-v7:28.0.0"
Run Code Online (Sandbox Code Playgroud)
以及承载以下内容的布局代码Fragment:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".ui.activity.MainActivity">
<android.support.v7.widget.Toolbar
android:id="@+id/mainToolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize" />
<fragment
android:id="@+id/navHostFragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:navGraph="@navigation/navigation" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
一切都很好,除了每个偏好左侧有一个巨大的空白区域:
这个问题的原因是什么,我该如何预防呢?
编辑:
似乎问题是图标的空间被保留,即使我们没有使用偏好条目的图标.
将icon首选项的属性设置为@null无效.
设置iconSpaceReserved属性以false解决Preference项目的问题,但它对PreferenceCategory项目没有影响.
如果使用AndroidX,请将以下属性添加到 XML 中的首选项(和首选项类别,如果需要):
<Preference
...
app:iconSpaceReserved="false"
.../>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
486 次 |
| 最近记录: |