默认情况下,是不是应该是动作条下? 所以我在做什么错?
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
RES /菜单/ main.xml中
<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.example.test.MainActivity" >
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="@string/action_settings"
app:showAsAction="never"/>
</menu>
按照材质设计规格 ,溢出菜单应显示在操作栏的顶部:
菜单是一张临时片总是重叠应用栏,而不是表现为应用栏的延伸。
这是Android棒棒糖应用以及使用该程序兼容性V7支持库的任何应用程序的默认行为。
这是您正在使用程序兼容性主题的默认行为。 根据材料的设计指导方针,预计溢出菜单出现在它的锚,在动作条上。
您可以通过是否设置你的主题迫使它显示操作栏下方overlapAnchor
到false
<style name="OverflowMenu" parent="Widget.AppCompat.PopupMenu.Overflow" >
<item name="overlapAnchor">false</item>
<item name="dropDownVerticalOffset">?attr/actionBarSize</item>
</style>
最后,这对我的作品:
<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>
来源: https://stackoverflow.com/a/27134045/3586815
感谢尼古拉Despotoski的提示。
这是新的默认与材料设计。 弹出菜单将显示从发起Button
开幕它们。
这样做是为了增加之间的视觉连接Button
,并在弹出菜单中。 只要看看谷歌的应用程序,其已经在使用材料设计,将有弹出菜单以同样的方式行事。