Android in customize activity and dialog position size background and transparency etc Demo

Source: Internet
Author: User
Tags set background

1. Customize Activity Display Style

First build the Colors.xml file under Res/values, write:

[XHTML]View Plaincopy
  1. <? XML version= "1.0" encoding="Utf-8"?>
  2. <resources>
  3. <!--Set the transparency to 56% (9/16) and so on
  4. <color name="Transparent"> #9000</color>
  5. </Resources>

This value sets the transparency of the entire interface, and is now set to about 56% (9/16) of the transparency to see the effect.

Then build Styles.xml under Res/values/, set the style of the program

[XHTML]View Plaincopy
  1. <? XML version= "1.0" encoding="Utf-8"?>
  2. <resources>
  3. <mce:style name="Transparent"><!--
  4. Set background--
  5. <item name="Android:windowbackground"> @color/transparent</Item>
  6. <!--set the bottom visible --
  7. <item name="android:windowistranslucent">true</Item>
  8. <!--set Jump effects --
  9. <item name="Android:windowanimationstyle">@+android:style/animation.translucent </Item>
  10. --></mce:style><style name="Transparent" mce_bogus="1" > Setting background-->
  11. <item name="Android:windowbackground"> @color/transparent</Item >
  12. <!--set the bottom visible --
  13. <item name="android:windowistranslucent">true</Item>
  14. <!--set Jump effects --
  15. <item name="Android:windowanimationstyle">@+android:style/animation.translucent </Item>
  16. </style>
  17. </Resources>

Note: The MCE section is automatically generated for postings and is not actually required.

The last step is to use this styles.xml in the corresponding activity. That is, add any <activity> tags in the androidmanifest.xml
Android:theme = "@style/transparent"
If you want to set all the activity to use this style, you can add this tag statement in <application>.
Finally run the program, Haha, is not found that the entire interface is covered with a layer of translucent. Finally can change the background color #9000 to #0000, after running the program, it is completely transparent, see the background of all things can be invalid operation. Oh....

2. Display the activity as dialog and customize the style

First build the Bgconfig.xml file under Res/drawable, write:

[XHTML]View Plaincopy
  1. <? XML version= "1.0" encoding="Utf-8"?>
  2. <shape xmlns:android="http://schemas.android.com/apk/res/android">
  3. <solid android:color="#ffffff" />
  4. <stroke android:width="3DP" color="#000000" />
  5. <corners android:radius="3DP" />
  6. <padding android:left="3DP" android:top="3DP" android:right="3DP"
  7. android:bottom="3DP" />
  8. </shape>

Then build Styles.xml under Res/values/, set the style of the program

[XHTML]View Plaincopy
  1. <? XML version= "1.0" encoding="Utf-8"?>
  2. <resources>
  3. <!--setting Styles --
  4. <mce:style name="theme.myactivity" parent="Android:style/theme.dialog" mce_bogus= "1" mce_bogus="1"><!--
  5. <item name= "Android:windowbackground" > @drawable/bgconfig</item>
  6. -</mce:style><style  name= "theme.myactivity"   Parent= "Android:style/theme.dialog"  mce_bogus= "1"  mce_bogus= "1"  < span class= "attribute" >mce_bogus= "1" >      <item name=" Android:windowbackground "> @drawable/bgconfig</< Span class= "Tag-name" >item>  
  7. </style>
  8. </Resources>

Note: The MCE section is automatically generated for postings and is not actually required.

The last step is to use this styles.xml in the corresponding activity. That is, add any <activity> tags in the androidmanifest.xml
Android:theme = "@style/transparent"
If you want to set all the activity to use this style, you can add this tag statement in <application>.

3. Setting the window size and position

[Java]View Plaincopy
    1. WindowManager m = Getwindowmanager ();
    2. Display d = m.getdefaultdisplay (); //To get the screen width, height
    3. Layoutparams p = GetWindow (). GetAttributes (); //Gets the current parameter value of the dialog box
    4. P.height = (int) (D.getheight () * 1.0); //Height set to 1.0 of the screen
    5. P.width = (int) (D.getwidth () * 0.7); //Width set to 0.8 of the screen
    6. P.alpha = 1.0f; //Set itself transparency
    7. P.dimamount = 0.0f; //Set Dark degrees
    8. GetWindow (). SetAttributes (P); //settings take effect
    9. GetWindow (). setgravity (Gravity.right); //Set Align Right

Android in customize activity and dialog position size background and transparency etc Demo

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.