Custom dialog of Android UI design series to achieve various styles of dialog effects (7)

Although Android provides us with many components, they are not very convenient to use. The APK we develop has its own style. If we use the components of the system, we always feel that they are irrelevant to the theme of the application and don't look satisfactory, we need to customize them. In order to facilitate everyone's study of custom components, Next, I prepared several articles about custom dialog, hoping to be helpful to you. In the development of APK, the most common estimation pop-up dialog box is divided into three types according to the number of buttons: one button, two buttons and three buttons. Now I want to talk about the above three categories according to the number of buttons (of course, there can be more buttons as long as you like). There are three steps to customize the dialog: the first step is to redefine the dialog style, the second step is to define the layout file we need to display, and the third step is to set the event listener. Well, it's the old rule. First, paste the project directory:

In the project, I defined a base class, basebean, which is used as the base class in the whole project. The base class defines some common properties. If other properties are needed, we only need to inherit the base class. Therefore, I defined dialogbean, which inherits the basebean, so it has all the functions of basebean. Let's first look at what is defined in the basebean:

The above is the content of the base class. Let's take a look at the definition in dialog:

The code comments in dialogbean are very detailed, so I won't explain more. It mainly encapsulates the common properties in the dialog box. Next, let's take a look at the required dialog style defined:

The style mainly defines that the dialog box has no title and the background color is transparent. Now that the required style is defined, the protagonist globaldialog should appear. The code is as follows:

After writing the code of the customized globaldialog, let's see how to use it:

There's really nothing to explain about the code. I'm sure you'll see it at a glance. Let's see the operation effect:

The interface looks a little ugly. You can modify the color value or use pictures instead.

Well, here's the custom dialog to realize the dialog boxes with different styles and effects. Thank you for reading.

Source download: Android UI design to achieve various styles of dialog box effects

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