CoordinatorLayout 工具栏在输入时不可见,直到全高
CoordinatorLayout Toolbar invisible on enter until full height
我的activity_main.xml的DrawerLayout
中包含一个名为content_layout.xml[=的CoordinatorLayout
37=]。在这个 CoordinatorLayout
中,我的 AppBarLayout
包含一个 Toolbar
,然后是一个 LinearLayout
片段的内容。
当包含RecyclerView
的片段向上滚动时,工具栏成功退出。问题出在向下滚动以返回工具栏时。直到工具栏的整个高度被滚动后,工具栏才会出现,因此会在其位置留下一个难看的白色框,如图所示。
content_layout.xml
<android.support.design.widget.CoordinatorLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container_frame"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.AppBarLayout>
<!-- The main content view for fragments-->
<LinearLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
工具栏通过 MainActivity
的 onCreate()
:
初始化
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
对于解决此问题的任何建议,我将不胜感激。谢谢。
我遇到了同样的问题,我发现唯一能解决这个问题的方法是在 AppBarLayout
中添加 toolbar
以外的东西。我在工具栏下方的布局中放置了一个不可见的视图。不是最理想的解决方案,但它有效。
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
<View
android:id="@+id/appbar_bottom"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:color/transparent"
android:visibility="invisible"/>
</android.support.design.widget.AppBarLayout>
我的activity_main.xml的DrawerLayout
中包含一个名为content_layout.xml[=的CoordinatorLayout
37=]。在这个 CoordinatorLayout
中,我的 AppBarLayout
包含一个 Toolbar
,然后是一个 LinearLayout
片段的内容。
当包含RecyclerView
的片段向上滚动时,工具栏成功退出。问题出在向下滚动以返回工具栏时。直到工具栏的整个高度被滚动后,工具栏才会出现,因此会在其位置留下一个难看的白色框,如图所示。
content_layout.xml
<android.support.design.widget.CoordinatorLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container_frame"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.AppBarLayout>
<!-- The main content view for fragments-->
<LinearLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
工具栏通过 MainActivity
的 onCreate()
:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
对于解决此问题的任何建议,我将不胜感激。谢谢。
我遇到了同样的问题,我发现唯一能解决这个问题的方法是在 AppBarLayout
中添加 toolbar
以外的东西。我在工具栏下方的布局中放置了一个不可见的视图。不是最理想的解决方案,但它有效。
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
<View
android:id="@+id/appbar_bottom"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:color/transparent"
android:visibility="invisible"/>
</android.support.design.widget.AppBarLayout>