Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
646 views
in Technique[技术] by (71.8m points)

android - How to show menu popup exact below actionbar?

I am working on popup-menu in actionbar. But I am stuck to display exact below of actionbar(cut-to-cut).I am putting two snapshot.

My issue screen shot:

enter image description here

I want exact popup menu below of actionbar as below screenshot

Correction screenshot:

enter image description here

My code snippet:

<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=".MainActivity">
<item android:id="@+id/action_filter"
    android:icon="@drawable/ic_filter_white_18dp"
    android:title="@string/action_filter"
    app:showAsAction="ifRoom" />
<item android:id="@+id/action_label"
    android:icon="@drawable/ic_add_circle_outline_white_18dp"
    android:title="@string/action_label"
    app:showAsAction="ifRoom" />
<item android:id="@+id/action_settings"
    android:title="@string/action_settings"
    app:showAsAction="never" />

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

When working with AppCompat Theme, below code help you.Either Kitkat or Lollipop

Make your style.xml like below

<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/black</item>
    <item name="android:background">@android:color/transparent</item>
    <item name="actionOverflowMenuStyle">@style/OverflowMenu</item>
</style>


<style name="OverflowMenu" parent="Widget.AppCompat.PopupMenu.Overflow">
    <item name="android:windowDisablePreview">true</item>
    <item name="overlapAnchor">false</item>
    <item name="android:dropDownVerticalOffset">5.0dp</item>
    <!--<item name="android:popupBackground">#FFF</item>-->
</style>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...