如何将Android Snackbar的初始对齐方式从底部更改为顶部? [英] How do I change an Android Snackbar's initial alignment from bottom to top?

查看:399
本文介绍了如何将Android Snackbar的初始对齐方式从底部更改为顶部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近的android库是几天前发布的,但是我希望SnackBar出现在屏幕顶部,最好是在RelativeLayout中,因为它是其父视图.

The recent android library came out just a few days ago, but I would like to have the SnackBar appear on top of the screen, preferably within a RelativeLayout as it's parent view.

如何将我假定为layout_alignParentBottomSnackBar的初始对齐方式更改为layout_alignParentTop?

How does one change the SnackBar's initial alignment which I presume to be layout_alignParentBottom to layout_alignParentTop?

推荐答案

可以使用以下方法使小吃栏出现在屏幕顶部:

It is possible to make the snackbar appear on top of the screen using this:

Snackbar snack = Snackbar.make(parentLayout, str, Snackbar.LENGTH_LONG);
View view = snack.getView();
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams)view.getLayoutParams();
params.gravity = Gravity.TOP;
view.setLayoutParams(params);
snack.show()

注意:小吃店的动画从底部开始,并按预期激增到屏幕的顶部,因为根据ianhanniballake的回答,动画原本应该位于底部.

Note: The animation for the snackbar begins from the bottom and surges up to the top of the screen as expected because it was intended to be in the bottom as per ianhanniballake's answer.

对于从顶部涌动的通知,最好改用自定义"横幅.

For notifications surging from the top, it would probably better off getting a Custom banner instead.

这篇关于如何将Android Snackbar的初始对齐方式从底部更改为顶部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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