当我滚动ListView
在Fragment
我的ToolBar
不隐藏/显示。在Fragment
Android工具栏隐藏不起作用
<?xml version="1.0" encoding="utf-8"?>
<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.support.design.widget.AppBarLayout
android:id="@+id/home_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<include
layout="@layout/toolbar_layout"/>
<android.support.design.widget.TabLayout
android:id="@+id/home_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/home_viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
这我代码: 我用样品从here 这是我XML
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_home, container, false);
mViewPager = (ViewPager) view.findViewById(R.id.home_viewpager);
mAdapter = new HomeScreenPagerAdapter(getChildFragmentManager(), getActivity());
mViewPager.setAdapter(mAdapter);
mTabLayout = (TabLayout) view.findViewById(R.id.home_tabs);
mTabLayout.setupWithViewPager(mViewPager);
return view;
}
添加工具栏布局
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways|snap"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
我可以运行此代码,但ToolBar
不会隐藏。我怎样才能隐藏/显示它?
也发布您的toolbar_layout。另外,您尝试滚动的列表是否超出了您的屏幕尺寸? – Sevle
@Sevle补充说。是的 - 测试列表足够大(比屏幕大) – MyNameIs
我没有看到你的工具栏实现有什么问题。我只能推测,包含你的片段的列表视图的视图不支持可隐藏的工具栏。 (也许你将ListView封装在LinearLayout或简单的ScrollView中?)。尝试把你的ListView放在NestedScrollView下,并检查它是否有效。无论如何,如果你包含你的片段的布局xml,我可能会有更多的想法。 – Sevle