Tips for using Android custom pop-up window popupwindow

Popupwindow is a custom pop-up window on Android, which is very convenient to use.

The constructor for popupwindow is

Contentview is the view to be displayed, width and height are width and height, values are pixel values, or match_ Parent and wrap_ CONTENT。

Focusable is a very important parameter, which can also be set through public void setfocusable (Boolean focusable). If focusable is false, a popupwindow will pop up in an activity. Press the return key. Because popupwindow has no focus, it will exit the activity directly. If focusable is true, all touch screens and physical keys will be handled by popupwindows after popupwindow pops up.

If there is an editor in popupwindow, focusable should be true.

Here is a simple popupwindow

The layout of the main interface is:

The layout of popupwindow is:

The activity code is:

These three lines of code

The function of popupwindow is that popupwindow will disappear when you click on the blank space.

mPopupWindow.showAsDropDown(v); This line of code displays the popupwindow in the form of a downward pop-up animation

Public void showasdropdown (view anchor, int XOFF, int yoff) the first parameter of this function is a view. Here is a button, then popupwindow will be displayed under the button, and XOFF, yoff is the offset of the display position.

Click the button and popupwindow will be displayed

Many times, we use popupwindow as a custom menu, which requires a pop-up effect from the bottom, so we need to add animation to popupwindow.

Create an anim folder under project res, and create two XML files in the anim folder first

menu_ bottombar_ in.xml

menu_ bottombar_ out.xml

Add a sytle in RES / value / styles.xml

Activity is modified to

In this way, clicking the menu key will pop up the customized popupwindow. Click the blank space or the return key and menu key, and the popupwindow will disappear.

If there is something wrong with the article, I hope you can understand it.

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