Android custom pop-up menu and dialog function example code

During Android development, there may be many custom layout requirements, such as custom pop-up menus (popupwindow) and custom dialog boxes.

Don't say much, just go to the picture.

First, customize popupwindow

1.popupWindow

The layout of the pop-up menu is filled with listview, and then the background is changed due to the rounded background

Fillet background image of listview

Then you just call the showPopWindow () method in your logic code. OK, is it very simple?

Then I'll start talking about the custom dialog box, because this function is available in many apps, and the effect is good!

Take another look at the layout file of the dialog box: there is only one GridView and relativelayout

This is the layout file for setting the background of the dialog box. In fact, it mainly sets the fillet of the dialog box and the color of the dialog box as transparent!

Again, the purpose of using GridView here is to facilitate filling in more data in the future. If you use relative layout plus linear layout and write it dead, if you want to add data again in the future, you have to modify the layout, which is more troublesome! Because I have learned from the past, the following is the layout file I didn't use GridView to write before! Novice if you want to practice, you can try!

The effect is the same!

Then if you want to use the dialog box, just create a new dialog box!

summary

The above is the example code of Android custom pop-up menu and dialog function introduced by Xiaobian. I hope it will help you. If you have any questions, please leave me a message, and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

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
分享
二维码
< <上一篇
下一篇>>