1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Navigation+BottomNavigationViewでActivityにあるActionBarの戻るボタンを消す

Posted at

Navigation+BottomNavigationViewの実装方法はこの記事がわかりやすいです。

BottomNavigationView と Navigationを一緒に使う - Qiita

これで実装したときに、最初に表示されるFragment以外ではActionbarに「←」ボタンが表示されてしまいます。

ActivityのsetupActionBarWithNavControllerにトップレベルのFragmentのidをセットしたAppBarConfigrationを渡すことで消せます。

MainActivity.kt
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        Navigation.findNavController(this, R.id.nav_host_fragment).also {
            setupActionBarWithNavController(it,
                AppBarConfiguration(
                    //navigation.xmlに設定したidのセットを渡す
                    setOf(R.id.dest_home, R.id.dest_items)
                )
            )
            bottom_nav.setupWithNavController(it)
        }
    }
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?