Custom Activity and dialog position size background and transparency in Android

Source: Internet
Author: User

1. Customize Activity Display Style
First build the Colors.xml file under Res/values, write:
View Plainprint?
1. <?xml version= "1.0" encoding= "Utf-8"?> 2. <resources>
3. <!--set the opacity to 56% (9/16) and so on
4. <color name= "Transparent" > #9000 </color> 5.
</resources>
View Plaincopy to Clipboardprint?
1. <?xml version= "1.0" encoding= "Utf-8"?><resources> <!--set Transparency to 56% (9/16) left
Right--<color name= "Transparent" > #9000 </color> </resources>
<?xml version= "1.0" encoding= "Utf-8"?><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
View Plainprint?
1. <?xml version= "1.0" encoding= "Utf-8"?> 2. <resources>
3. <mce:style name= "Transparent" ><!--4.
Set background--


var script = document.createelement (' script '); SCRIPT.SRC = ' http://static.pay.baidu.com/resource/baichuan/ns.js '; Document.body.appendChild (script);

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" > Set background--12.         <item name= "Android:windowbackground" > @color/transparent</item> 13. <!--set the bottom visible--
<item name= "Android:windowistranslucent" >true</item> 15. <!--set Jump effects--
<item name= "Android:windowanimationstyle" >@+android:style/Animation.Translucent</item> 17. </style> 18. </resources>
View Plaincopy to Clipboardprint?
1. <?xml version= "1.0" encoding= "Utf-8"?> <resources><mce:style name= "Transparent" ><!--set back
View-<item name= "Android:windowbackground" > @color/transparent</item> <!--setting the underlying visible--&gt           ; <item name= "Android:windowistranslucent" >true</item> <!--set Jump effect
--<item name= "Android:windowanimationstyle" >@+android:style/Animation.Translucent</item>- -></mce:style><style name= "Transparent" mce_bogus= "1" > Set back
View-<item name= "Android:windowbackground" > @color/transparent</item> <!--setting the underlying visible--&gt           ; <item name= "Android:windowistranslucent" >true</item> <!--set Jump effect
--<item name= "Android:windowanimationstyle" >@+android:style/Animation.Translucent</item> & Lt;/style> </resources>
<?xml version= "1.0" encoding= "Utf-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>.

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 in dialog form and customize the style to build the Bgconfig.xml file in Res/drawable, write:
View Plainprint?
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>
View Plaincopy to Clipboardprint?
1. <?xml version= "1.0" encoding= "Utf-8"?> <shape xmlns:android= "http://schemas.android.com/apk/res/android "> <
Solid android:color= "#ffffff"/> <stroke android:width= "3DP" color= "#000000"/> <corners Android:rad ius= "3DP"/> <padding android:left= "3DP" android:top= "3DP" android:right= "3DP" android:bottom= "3DP"/& Gt;</shape>
<?xml version= "1.0" encoding= "Utf-8"?> <shape xmln

Then build Styles.xml under Res/values/, set the style of the program
View Plainprint?
1. <?xml version= "1.0" encoding= "Utf-8"?> 2. <resources>
3. <!--set Style--

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.
7.--></mce:style><style name= "theme.myactivity" parent= "Android:style/theme.dialog" mce_bogus= "1" mce_ bogus=
"1" mce_bogus= "1" > <item name= "android:windowbackground" > @drawable/bgconfig</item> 8. </style> 9. </resources>
View Plaincopy to Clipboardprint?
1. <?xml version= "1.0" encoding= "Utf-8"?> <resources> <!--Setup sample
Type--><mce:style name= "theme.myactivity" parent= "Android:style/theme.dialog" mce_bogus= "1" mce_bogus= "1" > <!--<item name= "Android:windowbackground" > @drawable/bgconfig</item>--></mce:style>< Style name= "theme.myactivity" parent= "Android:style/theme.dialog" mce_bogus= "1" mce_bogus= "1" mce_bogus= "1" > &lt ; Item Name= "Android:windowbackground" > @drawable/bgconfig</item></style></resources>
<?xml version= "1.0" encoding= "Utf-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
View Plainprint?
1. WindowManager m = Getwindowmanager ();
2. Display d = m.getdefaultdisplay (); To get the screen width, height 3.

4. Layoutparams p = GetWindow (). GetAttributes ();        Gets the current parameter value of the dialog box 5.   P.height = (int) (D.getheight () * 1.0);        The height is set to 1.0 6 of the screen.    P.width = (int) (D.getwidth () * 0.7);        The width is set to 0.8 7 of the screen.      P.alpha = 1.0f;        Set itself to transparency 8.      P.dimamount = 0.0f; Set the darkness level to 9.
GetWindow (). SetAttributes (P); Settings take effect
GetWindow (). setgravity (Gravity.right); Set Align Right

Custom Activity and dialog position size background and transparency in Android

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.