这是我的第一个堆栈溢出问题。如果我没有添加足够的数据或者我添加了太多细节,那就和我一起。位于操作栏/工具栏上方的Android溢出菜单?
我想让我的溢出菜单出现在我的应用程序顶部栏下方。当我使用Holo主题时,它做得很好,但我试图让我的应用程序使用appcompat v7库来使用材质设计。
所以,我的主题,现在从程序兼容性扩展:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/ucla_blue</item>
<item name="colorAccent">@color/caldroid_white</item>
<item name="android:actionMenuTextColor">@color/caldroid_black</item>
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
</style>
</resources>
这正常不应用材质的设计主题,以我的工具栏在此布局:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/linearlayout_root_main"
android:layout_height="match_parent"
android:layout_width="match_parent">
<!-- A DrawerLayout is intended to be used as the top-level content view using match_parent for both width and height to consume the full space available. -->
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_height="match_parent"
android:layout_width="match_parent"
tools:context="com.ucla.ieee.app.MainActivity">
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="?attr/colorPrimary"
android:id="@+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:minHeight="?attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
<!-- As the main content view, the view below consumes the entire
space available using match_parent in both dimensions. -->
<FrameLayout
android:id="@+id/container"
android:layout_height="match_parent"
android:layout_width="match_parent"/>
</LinearLayout>
<!-- The navigation drawer -->
<fragment
android:id="@+id/navigation_drawer"
android:layout_gravity="start"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"
android:layout_width="@dimen/navigation_drawer_width"
android:name="navigation.NavigationDrawerFragment"
tools:layout="@layout/fragment_navigation_drawer"/>
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
但由于某些原因,菜单我在onCreateOptionsMenu中膨胀出现在错误的地方。显然我不能发布图像,但基本上溢出菜单覆盖工具栏,而不是出现在工具栏下方。当我在普通的ActionBar中首先使用“Theme.AppCompat”,甚至现在使用工具栏时,就开始发生这种情况。
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
switch (selected) {
case FRONT_PAGE:
toolbar.inflateMenu(R.menu.main_settings);
return false;
case ANNOUNCEMENTS:
toolbar.inflateMenu(R.menu.refresh_settings);
return false;
case MEMBERSHIP:
toolbar.inflateMenu(R.menu.edit_member);
return false;
case CALENDAR:
toolbar.inflateMenu(R.menu.refresh_settings);
return false;
case POINTS_REWARDS:
toolbar.inflateMenu(R.menu.main_settings);
return false;
case HELP:
toolbar.inflateMenu(R.menu.main_settings);
return false;
default:
toolbar.inflateMenu(R.menu.main_settings);
}
似乎找不到任何人遇到这种情况,我希望有人能帮我弄清楚这一点!谢谢!
这是我的菜单中的一个的示例:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="com.ucla_ieee.app.MainActivity">
<item android:id="@+id/action_refresh"
android:title="@string/action_refresh"
app:showAsAction="never" />
</menu>
谢谢,但我已经在我的主要活动中这样做了。这并不是菜单不起作用,它只是看起来不正确:http://i.imgur.com/0ybW1A9.png – Tania 2014-10-29 20:17:07
根据您的屏幕截图更新了我的答案:您所看到的是一个Material Design菜单。 – ianhanniballake 2014-10-29 20:22:09
哦,该死,猜猜我实施Material Design的应用程序给了我错误的想法。谢谢!! – Tania 2014-10-29 20:34:30