Original address: http://blog.csdn.net/sodino/article/details/5822147
1.Activity Full Transparency
Classmate Zzm gave this interesting code, which is now published.
First build the Colors.xml file under Res/values, write:
<? XML Version = "1.0" ?> <> < Color = "Transparent"></> </ >
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
<?XML version= "1.0" encoding= "Utf-8"?><Resources> <stylename= "Transparent"><item name= "Android:windowbackground" > @color/transparent</item> <item name= "Android:win Dowistranslucent ">true</item> <item name=" Android:windowanimationstyle ">@+android:style/animation . Translucent</item></style></Resources>
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.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> <stylename= "Tancstyle"Parent= "@android: Style/theme.dialog"><!--Replace the background image for full transparency--<item name= "Android:windowbackground" > @drawable/panel_background_sodin o1</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> <stylename= "TitleStyle"Parent= "@android: Style/dialogwindowtitle"><item name= "android:textappearance" > @style/titletext</item></style> <stylename= "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:
<?XML version= "1.0" encoding= "UTF-8"?> <Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:background= "#0000"> <ScrollViewAndroid:id= "@+id/scrollview01"Android:layout_width= "Wrap_content"Android:layout_height= "200px"Android:layout_below= "@+id/imageview01"Android:background= "#0000"> <TextViewAndroid:id= "@+id/textview01"Android:text= "Sodinotext"Android:textcolor= "#f000"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:background= "#0000" ></TextView> </ScrollView> <ButtonAndroid:id= "@+id/btncancel"Android:layout_below= "@id/scrollview01"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_centerhorizontal= "true"Android:text= "Cancel"> </Button> </Relativelayout>
The 4.Activity code is as follows:
PackageLab.sodino.tanc; Importandroid.app.Activity; ImportAndroid.app.Dialog; ImportAndroid.os.Bundle; ImportAndroid.view.View; ImportAndroid.widget.Button; ImportAndroid.widget.TextView; Public classTancactextendsActivity {/**Called when the activity is first created.*/@Override Public voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.main); Button Btnshow=(Button) Findviewbyid (r.id.btnshow); Btnshow.setonclicklistener (NewButton.onclicklistener () { Public voidOnClick (view view) {Showtanc ("This is my custom dialog box", "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. ", "Http://blog.csdn.net/sodino"); } }); } Private voidShowtanc (string header, string content, string url) {FinalDialog Dialog =NewDialog ( This, R.style.tancstyle); Dialog.setcontentview (R.layout.main_dialog); Dialog.settitle (header); Dialog.setcancelable (true); TextView textView01=(TextView) Dialog.findviewbyid (R.ID.TEXTVIEW01); Textview01.settext (Content+ content +content); Button Btncancel=(Button) Dialog.findviewbyid (r.id.btncancel); Btncancel.setonclicklistener (NewButton.onclicklistener () { Public voidOnClick (view view) {Dialog.cancel (); } }); Dialog.show (); } }
At last:
Android Fun full Transparency Effect--activity and dialog full transparency (with Android system comes with icon Daquan) [Go]