0

I'm using the navigation drawer which uses the nav_header.xml (inside menu folder) as the top.

I'm trying to to change a textview text inside of it, this is the code:

toolbar = findViewById(R.id.toolbar)
setSupportActionBar(toolbar)

drawerLayout = findViewById(R.id.drawer_layout)
navView = findViewById(R.id.nav_view)

val toggle = ActionBarDrawerToggle(
    this, drawerLayout, toolbar, 0, 0
)
drawerLayout.addDrawerListener(toggle)
toggle.syncState()
navView.setNavigationItemSelectedListener(this)

val nickname = "testttt"

MenuNickname.text = nickname

The error is:

MenuNickname must not be null

How am I suppose to do this?

1 Answers1

0

This is the solution:

val nickname = "testttt"

var headerLayout = navView.getHeaderView(0)

headerLayout.MenuNickname.text = nickname

based on this answer:

NavigationView get/find header layout