LoginSignup
1
1

More than 3 years have passed since last update.

【Android】NavigationDrawer開閉時、ハンバーガーアイコンの回転アニメーションを無効化する方法

Posted at

はじめに

DrawerLayout、NavigationView、Toolbarを使ったActionBarの管理を行う際、
ActionBarDrawerToggleを使ってDrawerLayoutへ紐付けてハンバーガーアイコン()を表示している方が多いかと思います。

その際何も設定しないと、Drawerの開閉時にアイコンが回転するアニメーションが発生します。
オフにする場合はこちらで書かれている通り、onDrawerSlideで対応することができますが
もっと簡単な方法がありますので、自分用のメモついでに書かせていただきます。

対応方法


// トグルの生成
val toggle = ActionBarDrawerToggle(activity, drawerLayout, toolbar, R.string.open_drawer, R.string.close_drawer)

// アイコンのアニメーションのON/OFF
toggle.isDrawerSlideAnimationEnabled = false

// DrawerLayoutへトグルを紐付け
drawerLayout.addDrawerListener(toggle)

これだけです。
isDrawerSlideAnimationEnabledをfalseにすることにより、ハンバーガーアイコンをタップした際のアニメーションをオフにできます。

一応、トグル生成時の引数の説明を書いておきます。

1.Activity
2.DrawerLayout
3.Toolbar
4.「引き出しを開く」アクションを説明する文字列リソース
5.「引き出しを閉じる」アクションを説明する文字列リソース

第4、5引数に関しては適当な文字列で問題ないかと思います。

引用元

https://qiita.com/nissiy/items/b0c98cf210b7fe8833a7
https://qiita.com/CUTBOSS/items/c1eeda5df0da757a00f9
http://y-anz-m.blogspot.com/2017/05/

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1