For the More Curious: Accessing the AppCompat App Bar
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
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 ...