Android implementation bottom dialog box bottomdialog pop-up example code

Recently, the project needs to implement a bottom dialog box. To realize such a function, it is actually very simple. First look at the code:

Style of dialog box:

If the buttons in the dialog box need MD style ripple effect, the style parent of the dialog box needs to be set with parent = "@ style / base. V7. Theme. Appcompat. Light. Dialog", otherwise it has no effect. At the same time, remove the title of the window where the dialog box is located. Android: the windowbackground property must be set to transparent, otherwise the dialog box background of the custom shape will be white by default. If it is not set to transparent, for example, the fillet dialog box we usually set will have no effect.

Enter from the bottom when the dialog box is displayed and slide out from the bottom when it is closed. Animation style:

tranlate_ dialog_ in.xml:

tranlate_ dialog_ out.xml:

The principle of implementing the bottom dialog box is to modify the parameters of the content layout contentview of the dialog box so that its width is just equal to the width of the screen, and set the gravity property of the window where the dialog box is located to bottom.

It should be noted that in the above code, you need to call contentview. Getlayoutparams() after setcontentview method, otherwise the obtained layoutparams is null. Of course, you can also set a new layoutparams to contentview.

If you want to implement the bottom fillet dialog box, the principle is also similar. You only need to add a rounded background shape to the contentview, reduce the width of the contentview, leave a certain distance between the left and right sides, and set the margin at the bottom.

Source code: bottomdialog_ jb51.rar

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support 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
分享
二维码
< <上一篇
下一篇>>