Activity controls dialog style, display size and location

To meet the needs of project development, since the project is nearing completion, the user proposes to modify the condition filtering method. In order to achieve the minimum changes and meet the user's needs, all kinds of Baidu generally use popupwindow for dialog style. However, since the activity dialog method was used in the previous development and design, I'll introduce it to you today, How to achieve the same effect as popupwindow through activity? I don't have much nonsense. Let's start dry now.

To implement dialog style activity, we need to add a style declaration in androidmanifest.xml:

However, such dialog box style often can not meet our needs, and the display effect is not so satisfactory. The first point is how to control the size of the dialog box:

Add this control statement to the onclick () method of our dialog activity, so that our dialog can be as wide as the screen, LP. Gravity = gravity. Top// Set the dialog box to be displayed at the top. Android default dialog box is displayed in the middle. We can set the display position of the dialog box through this code.

Have you reached your satisfaction here? Now let's introduce how to achieve the display effect of clicking the plus sign in the upper right corner of wechat through activity. To make this display effect, we need to use Android: Layout in the layout file_ Margintop = "50dp" to adjust the position of the dialog box, the Android default pop-up box effect is very ugly. In order to achieve better display effect, we add a display animation effect here:

Enter Animation:

Exit Animation:

Android animation files are generally placed in the anim folder of res. by default, this folder does not exist and needs to be added manually.

Next, we need to add our animation to the Android style file: style.xml

Finally, we need to modify our declaration in the androidmanifest.xml file:

android:theme="@style/MyDialogTopRight"

Here we have perfectly realized the dialog style display of activity.

The above is the whole content of this article. I hope the content of this article can bring some help to your study or work. At the same time, I also hope to support a lot of 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
分享
二维码
< <上一篇
下一篇>>