Upgrade to Pro — share decks privately, control downloads, hide ads and more …

nacatl_slide_04_AAC_Navigation_Toolbar

nacatl
December 24, 2019
760

 nacatl_slide_04_AAC_Navigation_Toolbar

nacatl

December 24, 2019
Tweet

Transcript

  1. Copyright 2018 Studyplus, Inc. All Rights Reserved. Jetpack Navigation Toolbarのいろいろ

    Yuzuru Nakashima / Studyplus Inc. 2019.12.24 @ あるあるLT Vol.09
  2. Toolbar.setupWithNavController fun Toolbar.setupWithNavController( navController: NavController, configuration: AppBarConfiguration = AppBarConfiguration(navController.graph) )

    { NavigationUI.setupWithNavController( this, navController, configuration ) } このコンフィグで色々設定する
  3. Toolbar.setupWithNavController val navController = findNavController(R.id.nav_host_fragment) // TopLevelDestinationのSetを指定 val idSet =

    mutableSetOf<Int>() navController.graph.iterator() .forEach { idSet.add(it.id) } findViewById<Toolbar>(R.id.toolbar) .setupWithNavController( navController, AppBarConfiguration.Builder(idSet).build() )
  4. Toolbar.setupWithNavController val navController = findNavController(R.id.nav_host_fragment) // TopLevelDestinationのSetを指定(全部) val idSet =

    mutableSetOf<Int>() navController.graph.iterator() .forEach { idSet.add(it.id) } findViewById<Toolbar>(R.id.toolbar) .setupWithNavController( navController, AppBarConfiguration.Builder(idSet).build() ) graphにあるも の全部 add
  5. Toolbar.setupWithNavController - Tips. ドロワーの場合ハンバーガー出るらしい // androidx.navigation.ui.AbstractAppBarOnDestinationChangedListener boolean isTopLevelDestination = NavigationUI

    .matchDestinations( destination, mTopLevelDestinations ); if (drawerLayout == null && isTopLevelDestination) { setNavigationIcon(null, 0); } else { setActionBarUpIndicator( drawerLayout != null && isTopLevelDestination ); }
  6. onDestinationChangedListener // toolbar設定 setSupportActionBar(toolbar) supportActionBar?.let { it.setDisplayHomeAsUpEnabled(true) it.setHomeButtonEnabled(true) } //

    addOnDestinationChangedListener navController.addOnDestinationChangedListener { controller, destination, arguments -> supportActionBar?.title = destination.label // when(destination.id)でOptionMenu管理とか }
  7. 追加資料 - バックスタックない時の根拠(2.2.0-rc04の内部コード ) // androidx.navigation.ui.AppBarConfiguration /** * The {@link

    OnNavigateUpListener} that should be invoked if * {@link androidx.navigation.NavController#navigateUp} returns <code>false</code>. * @return a {@link OnNavigateUpListener} for providing custom up navigation logic, * if one was set. */ @Nullable public OnNavigateUpListener getFallbackOnNavigateUpListener() { return mFallbackOnNavigateUpListener; }