浮动操作按钮会出现在导航抽屉 [英] Floating Action Button appears over Navigation Drawer

查看:224
本文介绍了浮动操作按钮会出现在导航抽屉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我使用 https://github.com/neokree/MaterialNavigationDrawer 了解我的导航抽屉, https://gist.github.com/Jogan/9def6110edf3247825c9 我的FAB实施。当我打开抽屉式导航,它不包括FAB,按钮会出现在它的上面。我想避免隐藏按钮,显示在抽屉打开它/关闭,因为这是相当分散注意力。关于如何解决这个任何想法?

So I am using https://github.com/neokree/MaterialNavigationDrawer for my navigation drawer and https://gist.github.com/Jogan/9def6110edf3247825c9 as my FAB implementation. When I open the navigation drawer, it does not cover the FAB, and the button appears on top of it. I would like to avoid hiding the button and showing it on drawer open/close as that is rather distracting. Any ideas on how to fix this?

编辑:
我加入FAB编程执行以下操作:

I am adding the FAB programmatically doing the following:

fabButton = new FloatingActionButton.Builder(this)
            .withDrawable(getResources().getDrawable(R.drawable.ic_action_edit))
            .withButtonColor(0xFF2196F3)
            .withGravity(Gravity.BOTTOM | Gravity.END)
            .withMargins(0, 0, 16, 16)
            .create();

更改该声明的片段不解决它。导航栏实现我上面链接要求活动从MaterialNavigationDrawer类,它可以先画出导航抽屉延伸,使按钮始终是最后一个。有没有什么方法以编程方式强制元素的顺序?

Changing that declaration to the fragment does not fix it. The Nav Bar implementation I linked above requires the activity to extend from a MaterialNavigationDrawer class, which may draw the Nav Drawer first, leaving the button to always be last. Is there any way to programmatically force the ordering of the elements?

推荐答案

您看到FAB当导航抽屉是打开的,因为这FAB实现增加了FAB的内容视图( android.R.id.content )。根据导航抽屉实施,他们似乎是在视图层次结构相同的水平。

You see FAB when the navigation drawer is open because this FAB implementation adds FAB to the content view (android.R.id.content). Depending on the navigation drawer implementation they seem to be on same level in the view hierarchy.

如果你不想切换到不同的FAB实现。使用 onDrawerSlide(查看drawerView,浮偏移)并更改FAB阿尔法为您打开抽屉。你也可以切换其内可见 onDrawerClose() onDrawerOpen()方法了。

If you don't want to switch to different FAB implementation. Use onDrawerSlide(View drawerView, float offset) and change FAB alpha as you open the drawer. Also you could toggle its visibility inside onDrawerClose() or onDrawerOpen() methods too.

编辑:

@Override
public void onDrawerSlide(View drawerView, float offset){
   fabButton.setAlpha(offset);
}

这篇关于浮动操作按钮会出现在导航抽屉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆