Quantcast
Channel: Active questions tagged navigation - Stack Overflow
Viewing all articles
Browse latest Browse all 9966

Navigation Architecture Component - how to set/change custom back or hamburger icon with navigation controller?

$
0
0

I am trying to implement the newly introduced Navigation Architecture Component provided with Jetpack. as far it's very cool and useful for managing navigation flow of your app.

I have already setup the basic navigation including drawer layout with the toolbar in MainActivity like this:

class MainActivity : AppCompatActivity() {    override fun onCreate(savedInstanceState: Bundle?) {        super.onCreate(savedInstanceState)        setContentView(R.layout.activity_main)        val navController = Navigation.findNavController(this, R.id.mainNavFragment)        // Set up ActionBar        setSupportActionBar(toolbar)        NavigationUI.setupActionBarWithNavController(this, navController, drawerLayout)        // Set up navigation menu        navigationView.setupWithNavController(navController)    }    override fun onSupportNavigateUp(): Boolean {        return NavigationUI.navigateUp(Navigation.findNavController(this, R.id.mainNavFragment), drawerLayout)    }}

With this layout:

<LinearLayout    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical"><android.support.design.widget.AppBarLayout        android:id="@+id/appbar"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:theme="@style/AppTheme.AppBarOverlay"><android.support.v7.widget.Toolbar            android:id="@+id/toolbar"            android:layout_width="match_parent"            android:layout_height="?attr/actionBarSize"            app:popupTheme="@style/AppTheme.PopupOverlay"            app:navigationIcon="@drawable/ic_home_black_24dp"/></android.support.design.widget.AppBarLayout><fragment        android:id="@+id/mainNavFragment"        android:name="androidx.navigation.fragment.NavHostFragment"        android:layout_width="match_parent"        android:layout_height="match_parent"        app:defaultNavHost="true"        app:navGraph="@navigation/nav_main"/></LinearLayout>

It works fins. But, the real question is when provided custom design for an app,

how can I set custom icon for hamburger or the back icon?

which is as of now, being handled by NavigatoinController itself.

enter image description here

I already tried options below, but it doesn't work:

app:navigationIcon="@drawable/ic_home_black_24dp" //1supportActionBar.setHomeAsUpIndicator(R.drawable.ic_android_black_24dp) //2

Thanks!


Viewing all articles
Browse latest Browse all 9966

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>