簡體   English   中英

Android協調器布局:AppBarLayout下面的工具欄

[英]Android Coordinator Layout: Toolbar below AppBarLayout

我正在嘗試使用android設計支持庫開發一個簡單的測試應用,但我不明白為什么工具欄出現在AppBarLayout下方:

在此處輸入圖片說明

我的styles.xml是:

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>

    <!-- ActionMode -->
    <item name="windowActionModeOverlay">true</item>
    <item name="android:windowActionModeOverlay">true</item>
    <item name="android:actionModeBackground">@color/colorAccent</item>
    <item name="android:actionModeSplitBackground">@color/colorPrimary</item>
    <item name="android:actionModeStyle">@style/AppTheme.ActionMode</item>
</style>

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
</style>

<style name="AppTheme.ActionMode" parent="@style/Widget.AppCompat.ActionMode">
    <item name="android:background">?android:attr/actionModeBackground</item>
    <item name="android:backgroundSplit">?android:attr/actionModeSplitBackground</item>
    <item name="android:height">?android:attr/actionBarSize</item>
    <!--<item name="android:titleTextStyle">@android:style/TextAppearance.Widget.ActionMode.Title</item>
    <item name="android:subtitleTextStyle">@android:style/TextAppearance.Widget.ActionMode.Subtitle</item>-->
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

</resources>

我的布局是:

<?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"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">

<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>

<fragment android:id="@+id/items_fragment"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    class="it.bmsoftware.advancedrecyclerapp.MainFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:tag="items_fragment"
    tools:layout="@layout/fragment_recycler" />

</android.support.design.widget.CoordinatorLayout>

有誰知道我想念的東西嗎?

提前致謝 :)

AppbarLayout只是包裝工具欄以使其固定在操作欄上。 並再次查看代碼。

另一個問題是,您正在Android Studio的編輯器預覽中使用AppTheme,如果使用工具欄,然后選擇NoActionBar主題,那么這是不正確的,然后您將首先看到工具欄。 我認為您是在假設工具欄的Appbarlayout頂部,但實際上是其Actionbar。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM