Android implements the sample code of the custom fillet dialog box dialog

preface:

Many dialog boxes are used in the project. The system dialog box is too ugly, so I wrote a custom dialog box myself.

The dialog box includes: 1. Fillet

2. App icon, prompt text, and close the "OK" button of the dialog box

Difficulties: 1. Display of dialog box border fillet

2. Considering the uncertain number of words in the prompt text, the prompt text information needs to be displayed in one line without affecting the appearance

3. Set the width and height of the dialog box

Technical reserve:

1. Android Development_ Use alertdialog to implement the dialog box. You know that alertdialog has setview (view) and dialog has contentview (view) methods.

2. Android project practice (5): textview displays text information in an adaptive size line. When the number of text words is small, the text size is large, and when the number of text words is large, the text size is small.    

1. Layout

Where the root container uses

This is shape to set the edge fillet

2. As can be seen from the above, only a drawable file is required for the fillet of the setting dialog box, and the corners attribute of shape can be set.

You may find from other articles that some people use rounded background pictures to realize dialog box rounding, and some people use style to realize dialog box rounding.

After more than an hour of tossing, I found that these methods are not reliable. In fact, they are very simple. The above methods use alertdialog, but the dialog class we use here, a shape is enough.

Because there must be more dialog boxes in the project, I write a static method to pass the content of context parameters and prompt text:

1. Initialization dialog box related operations:

2. Set the click event of "OK" button

3. Display dialog box

4. Sets the width and height of the dialog box

Note: the width height ratio of the dialog box is set by the width height ratio of the screen.

There is another approach:

Dialog interface when there are many prompt texts:

Full code:

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