Android Custom Dialog box (Custom Dialog)

Source: Internet
Author: User

Now we want to implement a custom Dialog, mainly involving the style File style. Refer to the case and write your own code for implementation. First, create an Android Project -- CustomDialog, and then create an xml file filled_box.xml In the res/drawable folder. Its content is: <? Xml version = "1.0" encoding = "UTF-8"?> <Shape xmlns: android = "http://schemas.android.com/apk/res/android"> <solid android: color =" # ffff0000 "/> <stroke android: width = "3dp" color = "#00ffff80"/> <corners android: radius = "2dp"/> <padding android: left = "10dp" android: top = "10dp" android: right = "10dp" android: bottom = "10dp"/> </shape> This file mainly draws a rounded rectangle (shape android: the default value of the shape attribute is rectangle, so it is not set as a rectangle. The default value is a rectangle .), Set the fill color to # ffff0000, Which is solid. The rounded corner size is 2dp, Which is corners. the padding item mainly controls the alignment of each side, stroke items are mainly border effects. For more information about shape, see Dev Guide> Framework Topics> Application Resources> Resource Types> Drawable. The next step is to create the styles. xml style file in the res/values directory. The content is as follows: <? Xml version = "1.0" encoding = "UTF-8"?> <Resources> <style name = "Theme. customDialog "parent =" android: style/Theme. dialog "> <item name =" android: windowBackground "> @ drawable/filled_box </item> </style> </resources> Theme. customDialog is the name of a custom topic. The parent attribute specifies that the parent topic of a topic is android: style/Theme. dialog, this topic has been used in the case of "Dialog Prompt window", and then the window background is specified as the shape defined previously through filled_box through the item with name for android: windowBackground. Now that you have a theme style definition, you only need to add the theme items used for the Activity. The processing method of the previous case "Dialog Prompt window" is the same. Open AndroidManifest. xml file. Add the property android: theme = "@ style/Theme in the Activity definition. customDialog. Now you can run the project to see the custom effect.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.