actionbar.setHideOffset()导致强制关闭

时间:2015-02-02 17:15:02

标签: android android-actionbar-compat android-toolbar

我使用此代码使用AppCompact v7实现新的操作栏,一切都很好:

supportRequestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
setContentView(R.layout.activity_main);
mActionbar = getSupportActionBar();
mActionbar.setHideOffset(10);

但我必须使用xml工具栏才能使用新的动画导航抽屉指示器。 所以这是我的新activity_main xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="match_parent"
    android:layout_width="match_parent">

<android.support.v4.widget.DrawerLayout
    android:id="@+id/MainMenu_drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
<RelativeLayout
    android:id="@+id/contents"
    android:layout_height="match_parent"
    android:layout_width="match_parent">
</RelativeLayout>
<RelativeLayout
    android:id="@+id/list"
    android:layout_height="match_parent"
    android:layout_width="match_parent">
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
<android.support.v7.widget.Toolbar
        android:id="@+id/content_toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        style="@style/Actionbar"/>
</RelativeLayout>

这是我的新代码:

    supportRequestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
    setContentView(R.layout.activity_main);
    mToolbar = (Toolbar) findViewById(R.id.content_toolbar);
    setSupportActionBar(mToolbar);
    getSupportActionBar().setHideOffset(10);

强制关闭发生在最后一行。

它没有在logcat中显示任何错误,只是强制关闭!

抱歉英语不好:)

1 个答案:

答案 0 :(得分:0)

将其更改为

   getSupportActionBar().setHideOffset(0);
  

设置操作栏的当前隐藏偏移量。

     

操作栏的当前隐藏偏移量是动作的距离    栏目前在屏幕上以像素为单位滚动。有效范围是0    (完全可见)到操作栏的当前测量高度(完全可见)    不可见的)。