First, let's take a look at what is called a transparent progress dialog box:
Next we'll talk about how to create:
1. Use Eclipse to create a new Andr OID project that uses Android 2.2 or more.
2, in the/res/layout folder, create a linear layout activity_main.xml file, mainly to add a text label and a button
Copy Code code as follows:
Activity_main.xml
<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
android:orientation= "Vertical" >
<textview
android:layout_width= "Match_ Parent
android:layout_height= "wrap_content"
android:gravity= "Center_horizontal"
android:padding= "8DP"
android:textsize= "20SP"
android:text= "Transparent Progress indicator"/>
<button
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:text= "Check It out!"
android:layout_margintop= "40DP"
android:layout_gravity= "Center"
Android:id= "@+id/the_button"/>
</LinearLayout>
3, open the Styles.xml in/res/values, the style of the transparent dialog box will be added here. Be sure to specify the Parent property, or you may have problems running
Copy Code code as follows:
Styles.xml
<resources>
<!--
Base application theme, dependent on API Level. This theme was replaced
by Appbasetheme from Res/values-vxx/styles.xml on Newer devices.
<style name= "Appbasetheme" parent= "Android:Theme.Light" >
<!--
Theme customizations available in newer API levels can go in
& nbsp; Res/values-vxx/styles.xml, while customizations related to
backward-compatibility can go.
</style>
<!--application theme. -->
<style name= "Apptheme" parent= "Appbasetheme" >
<!--all customizations this are not specific to a particular api-level can go. -->
</style>
<!--Transparent Dialog-->
<style name= "Transparentprogressdialog" parent= "@android: Theme.dialog" >
<item name= "Android:windowframe" > @null </item>
<item name= "Android:windowbackground" > @android:color/transparent</item>
<item name= "Android:windowisfloating" >true</item>
<item name= "Android:windowcontentoverlay" > @null </item>
<item name= "Android:windowtitlestyle" > @null </item>
<item name= "Android:windowanimationstyle" > @android:style/animation.dialog</item>
<item name= "Android:windowsoftinputmode" >stateUnspecified|adjustPan</item>
<item name= "android:backgrounddimenabled" >true</item>
<item name= "Android:background" > @android:color/transparent</item>
</style>
</resources>
4, in the middle of the/res to add a dynamic rotation of the animated picture:
5, now can implement your Mainactivity.java file
Copy Code code as follows:
Mainactivity.java
Package com.authorwjf.transparentprogressdialog;
Import Android.os.Bundle;
Import Android.os.Handler;
Import android.app.Activity;
Import Android.app.Dialog;
Import Android.content.Context;
Import android.view.Gravity;
Import Android.view.View;
Import Android.view.View.OnClickListener;
Import Android.view.ViewGroup.LayoutParams;
Import Android.view.WindowManager;
Import android.view.animation.Animation;
Import Android.view.animation.LinearInterpolator;
Import android.view.animation.RotateAnimation;
Import Android.widget.ImageView;
Import Android.widget.LinearLayout;
public class Mainactivity extends activity implements Onclicklistener {
Private Transparentprogressdialog PD;
Private Handler H;
Private Runnable R;
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
h = new Handler ();
PD = new Transparentprogressdialog (this, r.drawable.spinner);
R =new Runnable () {
@Override
public void Run () {
if (pd.isshowing ()) {
Pd.dismiss ();
}
}
};
Findviewbyid (R.id.the_button). Setonclicklistener (this);
}
@Override
public void OnClick (View v) {
Pd.show ();
H.postdelayed (r,5000);
}
@Override
protected void OnDestroy () {
H.removecallbacks (R);
if (pd.isshowing ()) {
Pd.dismiss ();
}
Super.ondestroy ();
}
}
6, the following is the implementation of transparent animation code
Copy Code code as follows:
Private class Transparentprogressdialog extends Dialog {
Private ImageView IV;
Public Transparentprogressdialog (context context, int resourceidofimage) {
Super (context, r.style.transparentprogressdialog);
Windowmanager.layoutparams WLMP = GetWindow (). GetAttributes ();
wlmp.gravity = Gravity.center_horizontal;
GetWindow (). SetAttributes (WLMP);
Settitle (NULL);
Setcancelable (FALSE);
Setoncancellistener (NULL);
LinearLayout layout = new LinearLayout (context);
Layout.setorientation (linearlayout.vertical);
Linearlayout.layoutparams params = new Linearlayout.layoutparams (layoutparams.match_parent, LayoutParams.WRAP_ CONTENT);
IV = new ImageView (context);
Iv.setimageresource (Resourceidofimage);
Layout.addview (iv, params);
Addcontentview (layout, params);
}
@Override
public void Show () {
Super.show ();
Rotateanimation anim = new Rotateanimation (0.0f, 360.0f, Animation.relative_to_self,. 5f, Animation.relative_to_self,. 5f);
Anim.setinterpolator (New Linearinterpolator ());
Anim.setrepeatcount (Animation.infinite);
Anim.setduration (3000);
Iv.setanimation (ANIM);
Iv.startanimation (ANIM);
}
}
The final result is