操作栏中的下拉菜单与操作栏重叠

时间:2015-01-21 06:20:15

标签: android android-actionbar-compat

我在操作栏中有一个菜单

<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.Blog.gkgyan.MainActivity" >

    <item
        android:id="@+id/action_settings"
        android:orderInCategory="100"
        android:title="@string/action_settings"
        app:showAsAction="never"/>
    <item
        android:id="@+id/action_share"
        android:icon="@drawable/ic_action_share"
        android:orderInCategory="101"
        android:title="@string/action_share"
        app:showAsAction="always"/>
    <item
        android:id="@+id/action_rate"
        android:icon="@drawable/ic_action_important"
        android:orderInCategory="102"
        android:title="@string/action_rate"
        app:showAsAction="always"/>
    <item
        android:id="@+id/action_search"
        android:icon="@drawable/ic_action_search"
        android:orderInCategory="103"
        android:title="@string/action_search"
        app:showAsAction="always">
        <menu>
            <item
                android:id="@+id/menuSortNewest"
                android:showAsAction="never"
                android:title="Gk"/>
            <item
                android:id="@+id/menuSortRating"
                android:showAsAction="never"
                android:title="Current Affairs"/>
        </menu>
    </item>
    <item
        android:id="@+id/action_pin"
        android:icon="@drawable/ic_action_make_available_offline"
        android:orderInCategory="105"
        android:title="@string/action_pin"
         app:showAsAction="always"/>

</menu>

这是应用于菜单的样式

<resources>

    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.



    -->
    <style name="AppBaseTheme" parent="Theme.AppCompat.Light">
        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.



        -->

    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->

    </style>
    <!-- the theme applied to the application or activity -->
    <style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light">
        <item name="@android:actionBarStyle">@style/MyActionBar</item>

        <!-- Support library compatibility -->
        <item name="actionBarStyle">@style/MyActionBar</item>
    </style>

    <!-- ActionBar styles -->
    <style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
        <item name="android:background">@color/actionbar_background</item>
        <item name="overlapAnchor">false</item>

        <!-- Support library compatibility -->
        <item name="background">@color/actionbar_background</item>
    </style>
    </resources>

我的活动

用途

public class DetailActivity extends ActionBarActivity implements OnItemClickListener{

我的问题是创建了下拉菜单,但是它重叠了我试过的操作栏 <item name="overlapAnchor">false</item>然而它确实无法工作

我正在使用

import android.support.v7.app.ActionBarActivity;

目标和构建版本

android:minSdkVersion="8"
        android:targetSdkVersion="21" />

1 个答案:

答案 0 :(得分:3)

根据新的设计指南,这是所需的行为。您正在使用appCompat所以它应该发生。看到 Menus - Component

更新:如果您仍然不希望溢出菜单与操作栏重叠,则必须覆盖appCompat的溢出菜单样式。这可能有用

<resources>
    <style name="AppBaseTheme" parent="Theme.AppCompat.Light" />

    <style name="AppTheme" parent="AppBaseTheme">
        <item name="actionOverflowMenuStyle">@style/OverflowMenu</item>
    </style>

    <style name="OverflowMenu" parent="Widget.AppCompat.PopupMenu.Overflow">
        <!-- Required for pre-Lollipop. -->
        <item name="overlapAnchor">false</item>

        <!-- Required for Lollipop. -->
        <item name="android:overlapAnchor">false</item>
    </style>

</resources>