Khagendra
Khagendra

Reputation: 602

I am trying to implement navigation drawer in kotlin but getting an error

I am trying to implement android navigation drawer which is a part of navigation UI but while implementing it via kotlin i am getting an error that says unresolved error.

    class HomeActivity : AppCompatActivity(){
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)

            val appBarConfiguration = AppBarConfiguration(navController.graph, drawerLayout)

            setContentView(R.layout.activityhome)

        }
    }

Upvotes: 0

Views: 264

Answers (2)

Khagendra
Khagendra

Reputation: 602

We can use this instead of navigation UI if you don't want to use jetpack

    val drawwerlayout = drawer_layout
    val t = ActionBarDrawerToggle(this,drawwerlayout,R.string.drawer_open,R.string.drawer_close)
    drawwerlayout.addDrawerListener(t)
    t.syncState()

    supportActionBar?.setDisplayHomeAsUpEnabled(true)

    nav_view.setNavigationItemSelectedListener {
        when(it.itemId)
        {
            R.id.logout -> {
                Snackbar.make(homeLayout,"Logged out Clicked", Snackbar.LENGTH_SHORT).show()
            }
        }
        drawwerlayout.closeDrawer(GravityCompat.START)
        true
    }

Upvotes: 2

ianhanniballake
ianhanniballake

Reputation: 200130

As per the Navigation Declaring Dependencies documentation, the documentation assumes you are using the -ktx versions of the dependencies if you are writing in Kotlin.

The AppBarConfiguration(NavGraph, Drawerlayout) method is a Kotlin extension available only in the navigation-ui-ktx dependency.

Upvotes: 2

Related Questions