Go Android Fun full Transparency Effect--activity and dialog full transparency (with Android system comes with icon Daquan

Source: Internet
Author: User

Original: http://blog.csdn.net/sodino/article/details/58221471.Activity Full transparency

Classmate Zzm gave this interesting code, which is now published.

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

  1. <? XML Version = "1.0" encoding = "UTF-8" ?>
  2. < resources >
  3. < color name = "Transparent" > #9000 </ color > /c3>
  4. </ 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

    1. <?xml version= "1.0" encoding= "Utf-8"?>
    2. <resources>
    3. <style name= "Transparent" >
    4. <item name= "Android:windowbackground" > @color/transparent</item>
    5. <item name= "Android:windowistranslucent" >true</item>
    6. <item name= "Android:windowanimationstyle" >@+android:style/Animation.Translucent</item>
    7. </style>
    8. </resources>

The last step is to use this styles.xml in the corresponding activity. That is, add any <activity> tags in the androidmanifest.xml

    1. 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.Dialog Full Transparency

1. Prepare a fully transparent material that retains the border, such as:

2. Create a new Styles.xml file in the values, which reads as follows:

  • <?xml version= "1.0" encoding= "UTF-8"?>
    <resources>
    <style name= "Tancstyle" parent= "@android: Style/theme.dialog" >
    <!--to replace the background image for full transparency--
    <item name= "Android:windowbackground" > @drawable/panel_background_sodino1</item>
    <!--screen background is not dimmed--
    <item name= "android:backgrounddimenabled" >false</item>
    <!--change dialog box title bar--
    <item name= "Android:windowtitlestyle" > @style/titlestyle</item>
    </style>
    <style name= "TitleStyle" parent= "@android: Style/dialogwindowtitle" >
    <item name= "Android:textappearance" > @style/titletext</item>
    </style>
    <style name= "TitleText" parent= "@android: Style/textappearance.dialogwindowtitle" >
    <!--set the dialog title bar text color. -
    <item name= "Android:textcolor" > #000 </item>
    </style>
    </resources>

3. Under the Layout folder, create a new file sentence as Main_dialog.xml, as follows:

[XHTML]View Plaincopy
  1. <? XML version= "1.0" encoding="UTF-8"?>
  2. <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="wrap_content"
  4. android:layout_height="wrap_content"
  5. android:background="#0000">
  6. <ScrollView android:id="@+id/scrollview01"
  7. android:layout_width="wrap_content"
  8. android:layout_height="200px"
  9. android:layout_below="@+id/imageview01"
  10. android:background="#0000">
  11. <TextView android:id="@+id/textview01"
  12. android:text="Sodinotext"
  13. android:textcolor="#f000"
  14. android:layout_width="wrap_content"
  15. android:layout_height="wrap_content"
  16. android:background="#0000"
  17. ></TextView>
  18. </ScrollView>
  19. <button android:id="@+id/btncancel"
  20. android:layout_below="@id/scrollview01"
  21. android:layout_width="wrap_content"
  22. android:layout_height="wrap_content"
  23. android:layout_centerhorizontal="true"
  24. android:text="Cancel">
  25. </Button>
  26. </relativelayout>

The 4.Activity code is as follows:

[XHTML]View Plaincopy
  1. Package Lab.sodino.tanc;
  2. Import android.app.Activity;
  3. Import Android.app.Dialog;
  4. Import Android.os.Bundle;
  5. Import Android.view.View;
  6. Import Android.widget.Button;
  7. Import Android.widget.TextView;
  8. public class Tancact extends Activity {
  9. /** called when the activity is first created. */
  10. @Override
  11. public void OnCreate (Bundle savedinstancestate) {
  12. Super.oncreate (savedinstancestate);
  13. Setcontentview (R.layout.main);
  14. Button btnshow = (button) Findviewbyid (r.id.btnshow);
  15. Btnshow.setonclicklistener (New Button.onclicklistener () {
  16. public void OnClick (view view) {
  17. Showtanc (
  18. "This is my custom dialog box",
  19. "Textcontent/nwhen a dialog is requested for the first time, Android calls Oncreatedialog (int.) from your Activity, which is where you should instantiate the Dialog. This callback method is passed the same ID, that's passed to ShowDialog (int). After you create the Dialog, return the object at the end of the method. ",
  20. "Http://blog.csdn.net/sodino");
  21. }
  22. });
  23. }
  24. private void Showtanc (string header, string content, string url) {
  25. Final Dialog Dialog = new Dialog (this, r.style.tancstyle);
  26. Dialog.setcontentview (R.layout.main_dialog);
  27. Dialog.settitle (header);
  28. Dialog.setcancelable (TRUE);
  29. TextView textView01 = (TextView) Dialog.findviewbyid (R.ID.TEXTVIEW01);
  30. Textview01.settext (content + content + content);
  31. Button btncancel = (button) Dialog.findviewbyid (R.id.btncancel);
  32. Btncancel.setonclicklistener (New Button.onclicklistener () {
  33. public void OnClick (view view) {
  34. Dialog.cancel ();
  35. }
  36. });
  37. Dialog.show ();
  38. }
  39. }

At last:

Additional Android system comes with icon Daquan (1.5 1.6 2.1)

http://since2006.com/android/1.5-drawables.php

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.