You need to implement AppCompatCallback
and use AppCompatDelegate
. Here is a great article on how to use it: https://medium.com/google-developer-experts/how-to-add-toolbar-to-an-activity-which-doesn-t-extend-appcompatactivity-a07c026717b3# .nuyghrgr9 , and also check https://developer.android.com/reference/android/support/v7/app/AppCompatDelegate.html to find out which methods to delegate.
This class represents a delegate that you can use to extend AppCompat support for any Activity.
When using AppCompatDelegate you should use some methods, not an Activity method with the same name. It refers to:
addContentView(android.view.View, android.view.ViewGroup.LayoutParams)
setContentView(int)
setContentView(android.view.View)
setContentView(android.view.View, android.view.ViewGroup.LayoutParams)
requestWindowFeature(int)
invalidateOptionsMenu()
startSupportActionMode(android.support.v7.view.ActionMode.Callback)
setSupportActionBar(android.support.v7.widget.Toolbar)
getSupportActionBar()
getMenuInflater()
There are also some Activity lifecycle methods that need to be proxied for the delegate:
onCreate(android.os.Bundle)
onPostCreate(android.os.Bundle)
onConfigurationChanged(android.content.res.Configuration)
setTitle(CharSequence)
onStop()
onDestroy()
Sazid