小编Hol*_*fox的帖子

如何删除PreferenceScreen中的左缩进?

由于不推荐使用PreferenceFragment,因此我使用PreferenceFragmentCompat.

更换片段后,我从内容中得到左缩进:
更换片段后,我会从内容中删除缩进.

缩进很可能是因为图标而出现,但我不使用它们(默认是没有图标).

我试图将图标属性设置为android:icon="@null"android:color/transparent,但它没有帮助.

替换片段的功能:

private fun replaceFragment(fragment: Fragment) {
    supportFragmentManager.beginTransaction()
            .replace(R.id.fragment_layout, fragment)
            .commit()
}
Run Code Online (Sandbox Code Playgroud)

content_main.xml

<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"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".MainActivity"
    tools:showIn="@layout/app_bar_main">

    <FrameLayout
        android:id="@+id/fragment_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

我的设置片段:

class SettingsFragment : PreferenceFragmentCompat() {

companion object {

    /**
     * A preference value change listener that updates the preference's summary
     * to reflect its new value.
     */
    private val sBindPreferenceSummaryToValueListener = Preference.OnPreferenceChangeListener { preference, value ->

        val stringValue = value.toString()

        if (preference is ListPreference) …
Run Code Online (Sandbox Code Playgroud)

android android-preferences kotlin

11
推荐指数
2
解决办法
1043
查看次数

标签 统计

android ×1

android-preferences ×1

kotlin ×1