Android overflow menu positioned above actionbar/toolbar?

后端 未结 4 1269
谎友^
谎友^ 2020-12-06 10:08

I\'m trying to get my overflow menu to appear below the top bar in my app. When I was using the Holo theme it did this just fine, but I\'m trying to get my app to use materi

相关标签:
4条回答
  • 2020-12-06 10:59

    Check out the answer by @Girish Kumar at How I can place overflow menu below toolbar instead of overflow menu to overlaps the app bar. Shifting the overflow menu to the bottom of app bar is definitely possible.

    0 讨论(0)
  • 2020-12-06 10:59

    Some simple steps Go to android manifest file and search for the activity in which your dropdown menu is present, for mine it's welcome Activity Now press control and click on the theme name

    <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    

    you will move to the styles file where your theme is written once you go there, you

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>
    

    Now paste these two items there

    <item name="overlapAnchor">false</item>
    <item name="android:dropDownVerticalOffset">5.0dp</item>
    

    and you are done...

    P.S: Unfortunately I can't share the screenshot here, it seems like SO giving some error on adding images. But you can see on this link Image File

    0 讨论(0)
  • 2020-12-06 11:08

    If you change the theme of Activity in manifest than the overflow menu comes below the actionbar

    android:theme="@android:style/Theme.Holo.Light"
    
    0 讨论(0)
  • 2020-12-06 11:12

    Per the Material Design specifications (see the Menus section):

    A menu is a temporary sheet of paper that always overlaps the app bar, rather than behaving as an extension of the app bar.

    Menu overlap app bar

    So what you are seeing is the correct Material design for menus.

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