I'm building a Resume Builder App. For that I have to use view binding. In my app everting works well I'm able to create a view binding object of the variable with a particular layout. But when I call the views from the binding variable it's working in the .kt file but not while running the app. Binding object shows the view. But when I run the app it's not working as stated in the code.
class EducationActivity : AppCompatActivity() {
private lateinit var binding : ActivityEducationBinding
private lateinit var toolbar : Toolbar
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityEducationBinding.inflate(layoutInflater)
setContentView(R.layout.activity_education)
toolbar = findViewById(R.id.toolbar_eduction_activity)
setUpToolbar()
}
private fun setUpToolbar(){
setSupportActionBar(toolbar)
val actionBar = supportActionBar
if (actionBar!=null){
actionBar.setDisplayHomeAsUpEnabled(true)
actionBar.setHomeAsUpIndicator(R.drawable.ic_back_button_action_bar)
actionBar.setDisplayShowTitleEnabled(false)
}
toolbar.setNavigationOnClickListener { onBackPressed() }
}
The code above is working with : setSupportActionBar(toolbar)
but when I use, setSupportActionBar(binding.toolbarEducationActivity). It's not working while running the app. There is no error or anything. I didn't understand the problem. Thanks in advance!