工具栏在某些设备上不可见

时间:2015-10-16 18:40:43

标签: android toolbar android-appcompat

我有一个非常简单的布局,我使用附加功能动画显示/隐藏工具栏。我正在使用AppCompat和工具栏...

问题

有人报告从未显示过顶部工具栏。有什么想法吗?可能是什么原因?它在我的手机和其他人身上正常工作......

功能

public void showHideToolbar(boolean forceHide, boolean animate)
{
    L.d(this, "showHideToolbar: " + mShowToolbar);
    toolbar.clearAnimation();
    toolbar2.clearAnimation();
    if (mShowToolbar || forceHide)
    {
        if (animate) {
            toolbar.animate().translationY(-toolbar.getBottom()).setInterpolator(new AccelerateInterpolator()).start();
            toolbar2.animate().translationY(toolbar2.getBottom()).setInterpolator(new AccelerateInterpolator()).start();
        }
        else
        {
            toolbar.setTranslationY(-toolbar.getBottom());
            toolbar2.setTranslationY(toolbar2.getBottom());
        }
        mShowToolbar = false;
    }
    else
    {
        if (animate) {
            toolbar.animate().translationY(0).setInterpolator(new DecelerateInterpolator()).start();
            toolbar2.animate().translationY(0).setInterpolator(new DecelerateInterpolator()).start();
        }
        else
        {
            toolbar.setTranslationY(0);
            toolbar2.setTranslationY(0);
        }
        mShowToolbar = true;
    }
}

布局

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/flMain"
    android:background="?attr/main_background_color"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:elevation="4dp"
        app:theme="?actionBarThemeStyle"
        app:popupTheme="?actionBarPopupThemeStyle" />

    <android.support.v4.view
        android:id="@+id/vpSlides"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar2"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/bottom_bar_background"
        android:elevation="0dp"
        android:layout_alignParentBottom="true"
        android:gravity="top|start"
        app:theme="?actionBarThemeStyle"
        app:popupTheme="?actionBarPopupThemeStyle" >

    </android.support.v7.widget.Toolbar>

</RelativeLayout>

1 个答案:

答案 0 :(得分:0)

似乎即使您将工具栏设置为操作栏,也必须遵守xml中的布局排序。 setSupportActionBar无法将操作栏置于主要布局之上......

因此,简单的解决方案是将工具栏重新排序为内容......

我从来没有出现问题,因为通常我会在工具栏下面显示内容,在这里我不想这样,因此面临问题

相关问题