java - 带有 CollapsingToolbarLayout 的 PreferenceFragment

标签 java android layout

我想要像 Telegram 应用程序那样具有滚动 Activity 的偏好 fragment 。我在 FrameLayout 中使用了 android.support.v7.widget.RecyclerView 这是我的 Activity xml:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layoutDirection="rtl"
android:fitsSystemWindows="true">

<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar"
    android:layout_width="match_parent"
    android:layout_height="@dimen/app_bar_height"
    android:fitsSystemWindows="true"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/toolbar_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>

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

    <android.support.v7.widget.RecyclerView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
</FrameLayout>

这是我的 Activity 课:

public class SettingsActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_settings);
        getFragmentManager().beginTransaction()
                .replace(R.id.conddd, new MyPreferenceFragment())
                .commit();
        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            getWindow().setNavigationBarColor(0xFF4095c2);
        }
    }
}

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

问题是当我滚动 android.support.v7.widget.RecyclerView 工具栏不折叠

最佳答案

我已经使用 PreferenceFragmentCompat 解决了这个问题,而且效果很好! 但要使用它,您需要将 compile 'com.android.support:preference-v7:23.2.0' 添加到 build.gradle

关于java - 带有 CollapsingToolbarLayout 的 PreferenceFragment,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36217741/

相关文章:

java - 每次我单击 JEditorPane 中的超链接时,hyperlinkUpdate() 都会给我 NullPointerException?

方向改变时 Android TableLayout 重复

android - 在android中更改imageview的高度和宽度

android - 无样式 ViewPagerIndicator 与 SherlockActionBar 结合使用

java - TextField 大小和垂直对齐

Android:如何动态包含 XML 布局?

java - 与 Java Rest Web 服务的手动数据库连接( Jersey )

Java 检查给定的小时和分钟是否位于两个日期的小时和分钟之间

java - 无法在 AWS Ubuntu 实例上运行 Cassandra

Android 从相机获取全尺寸图像