Android uses popupwindow to implement custom daily

Android's popupwindow is a very useful widget. It can be used to realize the effect of floating window, such as a floating menu. The most common application is to make a toolbar in the video playback interface to control the playback progress. This paper uses popupwindow to implement a general daily, similar to alertdaily of Android system, to learn and master the use and implementation details of popupwindow and daily.

The interface effect is shown in the figure. After clicking the click button, a dialog box will pop up.

(1) . layout of customdaily

First, define the layout file of custdaily. As you can know from the alertdaily of the system, a dialog box contains three elements: title, that is, title, message, that is, the main content, and button, that is, OK and Cancel buttons, which are used to interact with users. Therefore, the layout design is as follows:

Where, shap_ Bg.xml is the definition file of the background of the daily log. You can modify this file to change the background of the daily log:

(2) . definition of customdaily

The interface of customdaily can be similar to the interface definition of alertdaily, mainly including the following methods:

1. Settitle sets the title 2. SetMessage sets the main content 3. Setpositivebutton sets the OK button 4. Setnegativebutton sets the Cancel button 5. Show 6. Dimiss disappears

It is defined as follows:

(3) . usage in activity

Since the popupwindow must be displayed to a parentview, the simplest way to use it in an activity is to pass the "root view" of the whole activity to the popupwindow, so that the daily log can be displayed in the middle of the whole screen. The method to obtain the root view of the activity is as follows:

findViewById(android.R.id.content)).getChildAt(0);

Therefore, the usage of cunstomdailog defined above is as follows:

So far, the implementation of the whole daily is introduced here.

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