热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Android溢出菜单位于操作栏/工具栏上方?-Androidoverflowmenupositionedaboveactionbar/toolbar?

Imtryingtogetmyoverflowmenutoappearbelowthetopbarinmyapp.WhenIwasusingtheHolo

I'm trying to get my overflow menu to appear below the top bar in my app. When I was using the Holo theme it did this just fine, but I'm trying to get my app to use material design using the appcompat v7 library.

我正在尝试将溢出菜单显示在我的应用中的顶部栏下方。当我使用Holo主题时,它做得很好,但我正在尝试使用appcompat v7库让我的应用程序使用材料设计。

So my theme now extends from AppCompat:

所以我的主题现在扩展到AppCompat:



    
    

And this properly does apply the material design theme to my toolbar in this layout:

这恰当地将材质设计主题应用于此布局中的工具栏:


    
    

        

            
            
            
        


        
        

    

But for some reason, the menu I inflate in onCreateOptionsMenu appears in the wrong place. Apparently I can't post images but basically the overflow menu covers the toolbar instead of appearing just below the toolbar. This started happening when I use "Theme.AppCompat" first in a normal ActionBar and even now with a Toolbar.

但由于某种原因,我在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);
            }

Couldn't seem to find anyone experiencing this as well.

似乎无法找到任何经历过这种情况的人。

Here's an example of one of my menus:

这是我的一个菜单的示例:


    

4 个解决方案

#1


19  

Per the Material Design specifications (see the Menus section):

根据材料设计规范(参见菜单部分):

A menu is a temporary sheet of paper that always overlaps the app bar, rather than behaving as an extension of the app bar.

菜单是一张临时的纸张,总是与应用栏重叠,而不是表现为应用栏的扩展。

Menu overlap app bar

So what you are seeing is the correct Material design for menus.

所以你看到的是菜单的正确材料设计。

#2


1  

Check out the answer by @Girish Kumar at How I can place overflow menu below toolbar instead of overflow menu to overlaps the app bar. Shifting the overflow menu to the bottom of app bar is definitely possible.

请查看@Girish Kumar的答案,如何在工具栏下方放置溢出菜单而不是溢出菜单以重叠应用栏。将溢出菜单移到应用栏的底部绝对是可能的。

#3


0  

If you change the theme of Activity in manifest than the overflow menu comes below the actionbar

如果更改清单中活动的主题,则操作栏下方会显示溢出菜单

android:theme="@android:style/Theme.Holo.Light"

#4


0  

Some simple steps Go to android manifest file and search for the activity in which your dropdown menu is present, for mine it's welcome Activity Now press control and click on the theme name

一些简单的步骤转到android清单文件并搜索下拉菜单所在的活动,对于我的欢迎活动现在按下控件并单击主题名称


        
            
            
        
    

you will move to the styles file where your theme is written once you go there, you

一旦你去那里,你将移动到你的主题所写的样式文件


Now paste these two items there

现在粘贴这两个项目

false
5.0dp

and you are done...

你完成了......

P.S: Unfortunately I can't share the screenshot here, it seems like SO giving some error on adding images. But you can see on this link Image File

P.S:不幸的是我无法在这里分享屏幕截图,似乎SO在添加图片时出现了一些错误。但你可以在这个链接上看到图像文件


推荐阅读
  • 自动轮播,反转播放的ViewPagerAdapter的使用方法和效果展示
    本文介绍了如何使用自动轮播、反转播放的ViewPagerAdapter,并展示了其效果。该ViewPagerAdapter支持无限循环、触摸暂停、切换缩放等功能。同时提供了使用GIF.gif的示例和github地址。通过LoopFragmentPagerAdapter类的getActualCount、getActualItem和getActualPagerTitle方法可以实现自定义的循环效果和标题展示。 ... [详细]
  • 本文介绍了使用kotlin实现动画效果的方法,包括上下移动、放大缩小、旋转等功能。通过代码示例演示了如何使用ObjectAnimator和AnimatorSet来实现动画效果,并提供了实现抖动效果的代码。同时还介绍了如何使用translationY和translationX来实现上下和左右移动的效果。最后还提供了一个anim_small.xml文件的代码示例,可以用来实现放大缩小的效果。 ... [详细]
  • 欢乐的票圈重构之旅——RecyclerView的头尾布局增加
    项目重构的Git地址:https:github.comrazerdpFriendCircletreemain-dev项目同步更新的文集:http:www.jianshu.comno ... [详细]
  • 今天就跟大家聊聊有关怎么在Android应用中实现一个换肤功能,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根 ... [详细]
  • 在Android开发中,使用Picasso库可以实现对网络图片的等比例缩放。本文介绍了使用Picasso库进行图片缩放的方法,并提供了具体的代码实现。通过获取图片的宽高,计算目标宽度和高度,并创建新图实现等比例缩放。 ... [详细]
  • android listview OnItemClickListener失效原因
    最近在做listview时发现OnItemClickListener失效的问题,经过查找发现是因为button的原因。不仅listitem中存在button会影响OnItemClickListener事件的失效,还会导致单击后listview每个item的背景改变,使得item中的所有有关焦点的事件都失效。本文给出了一个范例来说明这种情况,并提供了解决方法。 ... [详细]
  • 本文介绍了OC学习笔记中的@property和@synthesize,包括属性的定义和合成的使用方法。通过示例代码详细讲解了@property和@synthesize的作用和用法。 ... [详细]
  • 本文介绍了在Linux下安装Perl的步骤,并提供了一个简单的Perl程序示例。同时,还展示了运行该程序的结果。 ... [详细]
  • XML介绍与使用的概述及标签规则
    本文介绍了XML的基本概念和用途,包括XML的可扩展性和标签的自定义特性。同时还详细解释了XML标签的规则,包括标签的尖括号和合法标识符的组成,标签必须成对出现的原则以及特殊标签的使用方法。通过本文的阅读,读者可以对XML的基本知识有一个全面的了解。 ... [详细]
  • 在开发app时,使用了butterknife后,在androidStudio打包apk时可能会遇到报错。为了解决这个问题,可以通过打开proguard-rules.pro文件进行代码混淆来解决。本文介绍了具体的混淆代码和方法。 ... [详细]
  • 本文介绍了Android 7的学习笔记总结,包括最新的移动架构视频、大厂安卓面试真题和项目实战源码讲义。同时还分享了开源的完整内容,并提醒读者在使用FileProvider适配时要注意不同模块的AndroidManfiest.xml中配置的xml文件名必须不同,否则会出现问题。 ... [详细]
  • JDK源码学习之HashTable(附带面试题)的学习笔记
    本文介绍了JDK源码学习之HashTable(附带面试题)的学习笔记,包括HashTable的定义、数据类型、与HashMap的关系和区别。文章提供了干货,并附带了其他相关主题的学习笔记。 ... [详细]
  • 近来有一个需求,是需要在androidjava基础库中插入一些log信息,完成这个工作需要的前置条件有编译好的android源码具体android源码如何编译,这 ... [详细]
  • 在一对一直播源码使用过程中,有时会出现软键盘切换闪屏问题,就是当切换表情的时候屏幕会跳动,因此要对一对一直播源码表情面板无缝切换进行优化。 ... [详细]
  • 云原生应用最佳开发实践之十二原则(12factor)
    目录简介一、基准代码二、依赖三、配置四、后端配置五、构建、发布、运行六、进程七、端口绑定八、并发九、易处理十、开发与线上环境等价十一、日志十二、进程管理当 ... [详细]
author-avatar
豆芽哥的马甲_206
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有