我正在使用棒棒糖和AppCompat-v7库中引入的新添加工具栏.我在设置工具栏时遵循了this guide,我注意到,当你调用一些可以打开上下文操作栏的东西(比如高亮显示文本以便复制/粘贴)时,它会将工具栏向下推到页面上.你可以在页面底部的图片中看到我在说什么:
所以,基本上,我是这样设置的.我在一个xml文件中定义了工具栏,该文件与include标记一起使用:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"/>
然后,我在我的视图中实例化它:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/root"
tools:context=".MainActivity">
<include
layout="@layout/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<!-- Rest of view -->
</LinearLayout>
在代码中,我这样设置:
// On Create method of activity:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
有人知道如何使上下文ActionBar位于工具栏之上吗?