Dialog for Android custom activity

Source: Internet
Author: User

The first step:

Defining Layout.xml Files

<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
Android:background= "@android: Color/transparent" //Background transparent
>
Step Two:
Define custom theme styles in the Style.xml file
 <!--dialog box style--> 
<style name= "Customdialog" parent= "@android: Style/theme.dialog";
<item Name= "Android:windowanimationstyle" > @android: style/animation.dialog</item>
<item name= "Android: Windowsoftinputmode ">STATEUNSPECIFIED|ADJUSTPAN</ITEM>
<item name=" Android:windowbackground "> @android:color/transparent</item>//Set Dialog Background
<item name= android:windowframe > @null </item >//dialog windowframe box is no
<item name= "android:windowisfloating" >true</item>//whether the activity is emerging
<item name= "Android:windowcontentoverlay" > @null </item>
<item name= "Android: Windowistranslucent ">false</item>//is translucent
<item name=" Android:windownotitle ">true</item> Whether to display the title
<item name= "android:backgrounddimenabled" >false</item>//whether the background is blurry
<item name= "Android:windowcloseontouchoutside" >true</item>  //Click Background to hide

</style>

Step Three:
Load layout file in activity file
Fourth Step:
Add custom theme Properties when configuring activity in the Mainfest.xml file
<activity android:name= ". Activity. Dialogactivity "
Android:theme= "@style/customdialog"/>

Fifth Step: Set Popup Dialog Content style
        WindowManager m = Getwindowmanager ();
Display d = m.getdefaultdisplay (); To get the screen width, height
Windowmanager.layoutparams p = GetWindow (). GetAttributes (); Gets the current parameter value of the dialog box
P.width = (int) (D.getwidth () * 0.95); Width is set to 0.8 of the screen
GetWindow (). SetAttributes (p); Settings take effect
GetWindow (). setgravity (Gravity.bottom); Set the bottom alignment
P.height = (int); Height set to 1.0 of the screen
   P.alpha = 1.0f; Set itself transparency
P.dimamount = 0.0f; Set Dark degrees


Dialog for Android custom activity

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.