I have an activity HomeView
which already extends another activity and it cannot extend AppCompatActivity
. But HomeView needs to have a Toolbar. Th
Actually, it is pretty simple:
public class YourActivity extends SomeActivity implements AppCompatCallback {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// create the delegate
delegate = AppCompatDelegate.create(this, this);
delegate.onCreate(savedInstanceState);
delegate.setContentView(R.layout.activity_details);
// add the Toolbar
Toolbar toolbar= (Toolbar) findViewById(R.id.toolbar);
delegate.setSupportActionBar(toolbar);
}
@Override
public void onSupportActionModeStarted(ActionMode mode) {
// leave it empty
}
@Override
public void onSupportActionModeFinished(ActionMode mode) {
// leave it empty
}
@Nullable
@Override
public ActionMode onWindowStartingSupportActionMode(ActionMode.Callback callback) {
return null;
}
That's it. Please, don't forget to set a AppTheme.NoActionBar
theme to YourActivity
in the AndroidManifest.xml
.