2014-10-29 94 views
1

新的Android工具栏使我们可以对操作栏做些什么,但我遇到了一个问题。我在我的活动布局中使用工具栏作为操作栏(现在我猜,'AppBar'是正确的名称)。当用户关注edittext时,系统会向上滚动内容以让用户看到该字段。它还可以向上滚动屏幕上的ToolBar。这是一个问题,因为导航位于工具栏上,现在对用户隐藏。工具栏滚动屏幕上的屏幕

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:app="http://schemas.android.com/apk/res-auto" 
      android:orientation="vertical" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 
    <Toolbar 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="?android:attr/actionBarSize"> 
    </Toolbar> 
</LinearLayout> 

我们该如何保持ToolBar?

+0

等待你在scrollview中有没有工具栏?当你做的时候,工具栏本身并没有滚动 – tyczj 2014-10-29 15:22:44

+0

这是上面的布局,减去EditTexts,图像等。没有滚动视图。使用android:Theme.Material.NoActionbar作为父主题。还注意到状态栏颜色也向上滚动。 – Patrick 2014-10-29 16:58:28

+0

@tyczj它在我的Nexus 5上以最新的5.0图像滚动。 – Patrick 2014-10-29 17:04:53

回答

1

您可以通过在工具栏下方放置一个ScrollView并在其中放置内容来完成此操作。还需要在活动上设置android:windowSoftInputMode =“adjustResize”。此外,为了避免按动工具栏的动作模式,添加此属性

android:windowActionModeOverlay="true" 
+0

如果您的工具栏对内容透明(如ImageView)有意显示在下面,则这不起作用。 – zyamys 2017-11-17 18:48:37