Android Custom Custom Dialog dialog box

Source: Internet
Author: User

  Now is going to implement a custom dialog, mainly involving style file style. Refer to the case, write your own code to achieve. First create an Android Project--customdialog, and then create an XML file Filled_box.xml under the Res/drawable folder, which reads:
<?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 (the default value of the shape's Android:shape property is rectangle, so it is not set to a rectangle and the default is a rectangle.) ), set its fill color to #ffff0000, is solid this, the fillet size is 2DP, is corners this item, padding key controls each side to have the alignment information, the stroke item mainly is the border effect. For more information about shape, please participate in the documentation dev Guide–>framework topics–>application resources–>resource types–> Drawable the content of the page.
The next step is to create a styles.xml style file in the Res/values directory, which reads:
<?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 the theme that you define, and the Parent property specifies that the theme's parental theme is Android:style/theme.dialog, which is in the theme " The dialog prompt window has been used in the case and then the window background is specified by the item named Android:windowbackground, which is previously defined by the Filled_box shape.
Now that you have a theme style definition, just add the subject item you want to use for the activity, as in the previous case, "Dialog Prompt window", Open the Androidmanifest.xml file, add the attribute android:theme= "@style/theme.customdialog" at the activity definition, and specify a theme that is a custom theme. Now you can run the project to see the effect of customization.

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.