728x90

 

I found a solution (thanks to user1506104) to changing the toolbar's title, which did not use getSupportActionBar().setTitle().

CollapsingToolbarLayout toolbarLayout = findViewById(R.id.toolbar_layout); 
Toolbar toolbar = findViewById(R.id.toolbar); 
setSupportActionBar(toolbar); 

mViewModel.getValue().observe(this, mValue -> { 
	toolbarLayout.setTitle(mValue); });

Where R.id.toolbar_layout is the CollapsingToolbarLayout that parents R.id.toolbar in the activity's respective layout resource.

I do not know why it works unfortunately.

 

Reference

 

https://stackoverflow.com/questions/60467526/how-to-execute-settitle-for-an-actionbar-in-an-activitys-observe-call-for-a-v

 

 

How to execute setTitle() for an ActionBar in an activity's observe call for a ViewModel's LiveData object?

In an activity file, when I write getSupportActionBar().setTitle(...) in an instantiated observer interface for a view model's LiveData value, the action bar's title doesn't change on the observabl...

stackoverflow.com

 

 

728x90

+ Recent posts