Help us understand the problem. What is going on with this article?

NavigationDrawer開閉時のハンバーガーボタンのアニメーションを無効にする方法

More than 3 years have passed since last update.

概要

ActionBarDrawerToggleを使用してNavigationDrawerを実装すると開閉時にハンバーガーボタンにアニメーションが付いてしまいますが、NavigationDrawerをToolbarに被せていると、このアニメーションがビミョーな感じになってしまいます。
今回はこのビミョーな感じになってしまう開閉時アニメーションを無効にする方法を紹介します。

before.gif

方法

以下のように、onDrawerSlide の第二引数に 0 を渡してあげるだけ。

SampleActivity.java
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
    actionBarDrawerToggle.onDrawerSlide(drawerView, 0);
}

これでアニメーションを無効にすることができます。

after.gif

補足

ActionBarDrawerToggle#onDrawerOpened の内部でハンバーガーボタンを矢印に変える処理が入っています。

ActionBarDrawerToggle.java
@Override
public void onDrawerOpened(View drawerView) {
    mSlider.setPosition(1); // これでハンバーガーボタンを矢印に変えています
    if (mDrawerIndicatorEnabled) {
        setActionBarDescription(mCloseDrawerContentDescRes);
    }
}

NavigationDrawerをToolbarに被せない場合は onDrawerOpened にも処理を書いてあげる必要があります。

SampleActivity.java
@Override
public void onDrawerOpened(View drawerView) {
    drawerToggle.onDrawerOpened(drawerLayout);
    actionBarDrawerToggle.onDrawerSlide(drawerView, 0);
}
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした