Quantcast
Channel: onCreateOptionsMenu is never called - Stack Overflow
Viewing all articles
Browse latest Browse all 13

Answer by Irene Anguita for onCreateOptionsMenu is never called

$
0
0

This happens because you have defined a Theme in your styles.xml that has something like:

<style name="AppTheme" parent="Theme.AppCompat.Light.**NoActionBar**">

You can manually create a toolbar, and then yo have to add it to your Activity.

The xml for the toolbar view could be something like:

<?xml version="1.0" encoding="utf-8"?><androidx.appcompat.widget.Toolbarxmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"android:layout_height="wrap_content"android:layout_width="match_parent"android:minHeight="?attr/actionBarSize"android:background="?attr/colorPrimary"android:elevation="4dp"android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"app:popupTheme="@style/ThemeOverlay.AppCompat.Light"></androidx.appcompat.widget.Toolbar>

Then, in the Activity, you have to "display" it :

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);setSupportActionBar(toolbar);ActionBar actionBar = getSupportActionBar();if (actionBar != null) {    actionBar.setDisplayShowTitleEnabled(false);}

And now, you can create the menu with the known onCreateOptionsMenu


Viewing all articles
Browse latest Browse all 13

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>