在材料设计中设置弹出菜单

时间:2015-05-19 08:38:12

标签: android material-design popupmenu

我在我的应用程序中设置了一个弹出菜单。但是我希望弹出材料设计。我该怎么做?

我的弹出菜单

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@+id/item_movies"
        android:showAsAction="ifRoom|withText"
        android:title="Movies"
        android:visible="true"/>
    <item
        android:id="@+id/item_music"
        android:showAsAction="ifRoom|withText"
        android:title="Music"
        android:visible="true"/>
    <item
        android:id="@+id/item_comedy"
        android:showAsAction="ifRoom|withText"
        android:title="Comedy"
        android:visible="true"/>

</menu>

它看起来像这样

enter image description here

我想要这样的东西

enter image description here

public void showPopup(View v) {
        PopupMenu popup = new PopupMenu(this.getApplicationContext(), v);
        MenuInflater inflater = popup.getMenuInflater();
        inflater.inflate(R.menu.song_popup, popup.getMenu());
        popup.show();

        /*Toast.makeText(this, "pop up test",
                Toast.LENGTH_LONG).show();*/
    }

style.xml

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/myPrimaryColor</item>
        <item name="colorPrimaryDark">@color/myPrimaryDarkColor</item>
        <item name="colorAccent">@color/myAccentColor</item>
        <item name="android:textColorPrimary">@color/myTextPrimaryColor</item>
        <item name="android:navigationBarColor">@color/myNavigationColor</item>
        <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>


        <item name="android:windowBackground">@color/myWindowBackground</item>
        <item name="android:windowContentTransitions">true</item>
    </style>

    <style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
        <item name="spinBars">true</item>
        <item name="color">@android:color/white</item>
    </style>

    <style name="ToolBarStyle" parent="">
        <item name="android:elevation">@dimen/toolbar_elevation</item>
        <item name="popupTheme">@style/ThemeOverlay.AppCompat.Light</item>
        <item name="theme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
    </style>
</resources>
  • 我试图在网格视图中实现这一点。(比如在谷歌播放音乐中)

1 个答案:

答案 0 :(得分:2)

尝试使用android.support.v7.widget.PopupMenu代替android.widget.PopupMenu