May 2022
Intermediate to advanced
688 pages
20h 12m
English
As you saw in this chapter, you can change the contents of the app bar by adding menu items. You can also change other attributes of the app bar at runtime, such as the title it displays.
To access the AppCompat app bar, you reference your AppCompatActivity’s supportFragmentManager property.
From CrimeFragment, it would look something like this:
val appCompatActivity = activity as AppCompatActivity
val appBar = appCompatActivity.supportActionBar as Toolbar
The activity that is hosting the fragment is cast to an AppCompatActivity. Recall that because CriminalIntent uses the AppCompat library, you made your MainActivity a subclass of AppCompatActivity, which allows you to access ...
Read now
Unlock full access