具有CollapsingToolbarLayout的PreferenceFragment [英] PreferenceFragment with CollapsingToolbarLayout
问题描述
我希望具有带有电报应用程序之类的滚动活动的首选项片段.我在FrameLayout
中使用了android.support.v7.widget.RecyclerView
这是我的活动xml:
I want to have preference fragment with scrolling activity like Telegram application. I used a android.support.v7.widget.RecyclerView
in FrameLayout
and this is my 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>
这是我的活动课:
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
工具栏时不会合拢
The problem is when I'm scrolling android.support.v7.widget.RecyclerView
toolbar don't collapse
推荐答案
我已经使用PreferenceFragmentCompat
解决了它,并且效果很好!
但是要使用它,您需要将compile 'com.android.support:preference-v7:23.2.0'
添加到build.gradle
I have solved it with using PreferenceFragmentCompat
and it's working great!
but for using that you need to add compile 'com.android.support:preference-v7:23.2.0'
to build.gradle
这篇关于具有CollapsingToolbarLayout的PreferenceFragment的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!