Preface: Because in the project need to use to update the display animation demand, so think of dialog, own definition dialog not difficult. There are a lot of tutorials on the web, but there is a problem when it comes to the need for dialog background transparency. Some of the methods on the Internet have not been implemented on my machine, only can be found in the twists and turns in a way to achieve. Though it's a bit troublesome. But after all, the effect is good.
This method is written here, one is to share with you, the second is to make a record, for the future needs.
Don't say, on the code:
The following is the dialog to define their own layout files, is to run the task, the reference can be.
<?XML version= "1.0" encoding= "Utf-8"?
><linearlayout xmlns:android= "http://schemas.android.com/apk/res/android" android:layout_width= "match _parent " android:layout_height=" match_parent " android:orientation=" horizontal " > < TextView android:layout_height= "wrap_content" android:layout_width= "wrap_content" android:text= " Running " android:textsize=" 18sp " /> <imageview android:id=" @+id/dialog_image " Android : layout_height= "wrap_content" android:layout_width= "wrap_content" android:layout_gravity= "center" /> </LinearLayout>
You define dialog, the code that runs the task is removed, and can be added to the OnCreate ().
/** * Run Status Dialog form * @author Administrator * */class Mydialog extends Dialog{imageview imageview;public mydialog (Context con Text) {super (context);//TODO auto-generated Constructor stub}public mydialog (Context Context,int theme) {Super (context , theme);//Todo auto-generated constructor stub} @Overrideprotected void OnCreate (Bundle savedinstancestate) {//Todo Aut O-generated method Stubsuper.oncreate (savedinstancestate);//Remove Activity title Requestwindowfeature (window.feature_no_ TITLE); Setcontentview (r.layout.dialog); Set Title ImageView = (ImageView) Findviewbyid (r.id.dialog_image);}}
Before the implementation. I have experimented with the method of setting flag in dialog, some say I can, but I didn't realize it. Also leave the code to take the test:
Cause dialog to lose focus Dialog.getwindow (). SetFlags (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);d Ialog.setcanceledontouchoutside (true);
The true approach is implemented using a style, which requires two resource files, a color, and a style.
<color name= "Transparent" > #00000000 </color>
<style name= "Dialog" parent= "@android: Style/theme.dialog" > <item name= "Android:windowframe" > @null </item><!--Border-- <item name= "android:windowisfloating" >true</item><!-- Floating now activity above-- <item name= "android:windowistranslucent" >false</item><!--Translucent--- <item name= "Android:windownotitle" >true</item><!--Untitled-- <item name= "Android: Windowbackground "> @color/transparent</item><!--Background Transparent-- <item name=" Android: Backgrounddimenabled ">false</item><!--Blur-- </style>
After you have set up the resource file. Generate the instance code at the time of invocation such as the following:
Mydialog dialog = new Mydialog (this,r.style.dialog);d ialog.show ();
This completes.
References: http://www.cnblogs.com/windlivefamily/articles/2133956.html
Android itself defines dialog and implements the ability to lose focus (background transparency)