How to specify the position of snackBar on the screen in Android and how to solve small problems

Android specifies the location of the snackBar on the screen

SnackBar often appears in the form of a small pop-up box at the bottom of the mobile phone screen or at the bottom left of the desktop, and at the top of all layers of the screen. If you want to specify where it appears on the screen, you can place the snackBar in android.support.design.widget.coordinatorlayout.

Add coordinatorlayout in relativelayout as follows:

Call snackBar. Make() with coordinatorlayout as the first parameter, as follows:

You can change the position of the snackBar by changing the position of the coordinator layout, such as setting Android: paddingbottom = "16dp".

A little problem with snackBar position display

The new project of Android studio will have a method to display snackBar by default, which has been useless. The official account of WeChat was seen two days ago. http://www.jianshu.com/p/996dc15d21be This article. It's well written and comprehensive. It has basic functions and style customization.

It is necessary to customize the display position, because this is different from toast. Toast will be displayed on the soft keyboard, and this will be blocked by the soft keyboard.

But when the position is set to

Setting the offset distance does not take effect

It turns out that some view's parent inherits FrameLayout, which should be noted

Of course, it's troublesome to write and display it yourself, and you have to deal with the display and hide animation

It is specified in animateviewin() and animateviewout() of snackBar. Java

There's a good one on GitHub https://github.com/AndreiD/TSnackBar

It is done according to the on the system, and then many small functions are added. First remember, if the project is used, download this to change it

In design_ layout_ There is a sentence in snackbar.xml

Remember to change this to top

So it can be displayed on it.

Then there is the corresponding animation r.anim.design_ snackbar_ In and r.anim.design_ snackbar_ out

But both are

It can be deleted without modification

I just saw a line in the final void showview() method public void ondississ (view view) of the system

But this sentence is deleted in tsnackbar. Well, let's pay attention to whether there is any other big difference

Summary: if it is displayed at the top for a long time, you can use GitHub's project, otherwise use the design library

summary

The above is the whole content of this article. I hope the content of this article has a certain reference value for your study or work. If you have any questions, you can leave a message. Thank you for your support for programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>