Android menu icons are not displaying when the API level is above 10

前端 未结 2 2034
被撕碎了的回忆
被撕碎了的回忆 2020-12-18 04:13

I am trying to test something with menu options in Android.. And I noticed that menu icons are not displaying if the targetSdkVersion is greater than 10...

相关标签:
2条回答
  • 2020-12-18 04:47
    <menu xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        tools:context="com.ktcmynewapp.MainActivity" >
    
        <item
            android:id="@+id/action_settings1"
            android:icon="@drawable/image1"`enter code here`
            android:orderInCategory="100"
            android:title="home1"
            app:showAsAction="never">
            <menu>
                <item
                    android:id="@+id/action_settings2"
                    android:icon="@drawable/image2"
                    android:orderInCategory="100"
                    android:title="home1"
                    app:showAsAction="never"/>
                <item
                    android:id="@+id/action_settings3"
                    android:icon="@drawable/image3"
                    android:orderInCategory="100"
                    android:title="home2"
                    app:showAsAction="never"/>
            </menu>
        </item>
        <item
            android:id="@+id/action_settings4"
            android:icon="@drawable/image2"
            android:orderInCategory="100"
            android:title="home2"
            app:showAsAction="never"/>
    
    </menu>
    

    In this code the outer menu items are showing without icons, but the inner sub-menu items are properly showing with icons.

    0 讨论(0)
  • 2020-12-18 04:53

    Starting with API Level 11 (Android Honeycomb) Android introduced a new concept for menus. Devices build for that API Level do not have a menu key anymore. Instead of showing a menu after a key is pressed there is a new UI Component: the Actionbar. The Actionbar now shows as much menu items as the space allows and after that creates a button that will show the rest of the menu items in an overlay.

    I would assume that you are using some kind of theme for your activity that prevents the Actionbar from appearing and therefore no menu items are visible. Also read the guide on how to support Tablets and Handsets to begin to understand how the new actionbar works.

    0 讨论(0)
提交回复
热议问题