Lollipop で導入された新しく追加されたツールバーと AppCompat-v7 ライブラリの使用に取り組んでいます。ツールバーのセットアップに関するこのガイドに従いました。コンテキスト アクション バーを表示する何かを呼び出すと (コピー/貼り付けのためにテキストを強調表示するなど)、ツールバーがページ上で押し下げられることに気付きました。ページの下部にある画像で、私が話していることを確認できます。
というわけで、基本的にはこんな感じに設定。インクルードタグで使用するxmlファイルで定義されたツールバーがあります。
<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);
Contextual ActionBar がツールバーの上に来るようにする方法を知っている人はいますか?