Android Menu not showing up

12,011

Solution 1

inflater.inflate(R.menu.my_menu, my_menu); 

That solved the code alone with removing
android:showAsAction="ifRoom"

Solution 2

I had a similar problem. I did not get any error, just the menu button didn't show up. I fixed the problem in Manifest.xml file by changing android:theme="@style/AppBaseTheme" (or any other theme compatible with minSDK) . Because I was messing with style.xml file and created my own. This caused the problem. May help.

Solution 3

Every thing look clean just clean and build your app. And also if these does not solve your problem once unistall the app and reinstall it.

also if your xml name is Menu.xml make it menu.xml... that is case sensitive

Share:
12,011
CsharpBeginner
Author by

CsharpBeginner

Building my first site in charp. Its been a crazy journy so far.

Updated on June 04, 2022

Comments

  • CsharpBeginner
    CsharpBeginner about 2 years

    Im trying to get a custom menu to show when the menu button is clicked on my phone. Its not showing at all.

    I have a register icon caled register.png in this folder /res/drawable. I have my my_menu.xml in a folder called /res/menu. Did I lay out my folders wrong or is there something wrong in my code below.

    I renamed menu.xml to my_menu.xml I changed my code and now im getting these errors:

    [2012-04-07 07:50:43 - HelloWebView] W/ResourceType( 1560): Bad XML block: no root element node found [2012-04-07 07:50:43 - HelloWebView] C:\Users\josh\workspace\HelloWebView\res\menu\my_menu.xml:4: error: No resource identifier found for attribute 'showAsAction' in package 'android'

    my_menu.xml

    <?xml version="1.0" encoding="utf-8"?>
    
    <menu xmlns:android="http://schemas.android.com/apk/res/android">    
        <item android:id="@+id/register"          
            android:icon="@drawable/register"          
            android:title="@string/register"          
            android:showAsAction="ifRoom"/>    
    
    </menu>
    

    Mainapp

    public class HelloWebViewActivity extends Activity {
        WebView mWebView;
    
        /** Called when the activity is first created. */
    
        public void onCreate(Bundle savedInstanceState) {    
            super.onCreate(savedInstanceState);    
            setContentView(R.layout.main);    
            mWebView = (WebView) findViewById(R.id.webview);    
            mWebView.getSettings().setJavaScriptEnabled(true);    
            mWebView.loadUrl("http://www.Google.com");
            mWebView.setWebViewClient(new HelloWebViewClient());
        }
    
        private class HelloWebViewClient extends WebViewClient {   
            @Override    
            public boolean shouldOverrideUrlLoading(WebView view, String url) {        
                view.loadUrl(url);        
                return true;    
            }}
    
        @Override  
        public boolean onKeyDown(int keyCode, KeyEvent event) {    
            if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {        
                mWebView.goBack();       
                return true;    
            }    
            return super.onKeyDown(keyCode, event);}
    
        @Override
        public boolean onCreateOptionsMenu(Menu my_menu) {    
        MenuInflater inflater = getMenuInflater();    
        inflater.inflate(R.menu.menu, my_menu);    
    
        return true;
        }
    }
    
    • Shubhayu
      Shubhayu about 12 years
      can u try renaming your menu.xml to something like main_menu.xml?
    • Jiang Qi
      Jiang Qi about 12 years
      whats your app API Level? android:showAsAction attribute is only on version above API 11.
    • CsharpBeginner
      CsharpBeginner about 12 years
      I think 10 Ill remove that line of code
  • CsharpBeginner
    CsharpBeginner about 12 years
    It is lower case. I do notice that this line of code may have an issue. inflater.inflate(R.menu.menu, menu); the second menu is in blue. Does my menu need to be named mymenu or something>
  • Markon
    Markon about 8 years
    I had the same issue, except that I had this property defined not only for the <application>, but for each <activity>.