现在的位置: 首页 > 综合 > 正文

Android 自定义ProgressDialog

2012年10月24日 ⁄ 综合 ⁄ 共 2397字 ⁄ 字号 评论关闭

(1)自定义DefineProgressDialog类,继承ProgressDialog,复写onCreate()方法

package com.lizhen.animation;

import com.lizhen.key.study.R;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.Bundle;
import android.widget.TextView;

public class DefineProgressDialog extends ProgressDialog{
	private String message;
	private TextView define_progress_msg;
	public DefineProgressDialog(Context context) {
		super(context);
		message = "正在载入...";
		// TODO Auto-generated constructor stub
	}
	public DefineProgressDialog(Context context,String message){
		super(context);
		this.message = message;
	}
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.define_progress_dialog);
		define_progress_msg = (TextView) findViewById(R.id.define_progress_msg);
		define_progress_msg.setText(message);
	}
	
}

 

(2)define_progress_msg.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/progress_bg"
    android:orientation="vertical"
    android:paddingBottom="10sp"
    android:paddingTop="10sp"
    android:paddingLeft="10sp"
    android:paddingRight="10sp" >
    <ProgressBar 
        android:id="@+id/ios_progressbar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        style="@style/DefineprogressBarStyleSmall"/>
	<TextView 
	    android:id="@+id/define_progress_msg"
	    android:layout_width="wrap_content"
	    android:layout_height="wrap_content"
	    android:layout_gravity="center_horizontal"
	    android:textSize="12sp"/>
</LinearLayout>

 

(3)设置进度条样式,自定义DefineprogressBarStyleSmall,在style中添加define_progressbar:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="DefineprogressBarStyleSmall" parent="android:style/Widget.ProgressBar">
		<item name="android:indeterminateDrawable">@drawable/progress</item>
		<item name="android:minWidth">48dp</item>  
        <item name="android:maxWidth">48dp</item>  
        <item name="android:minHeight">48dp</item>  
        <item name="android:maxHeight">48dp</item> 
	</style>
</resources>

(4)再定义一个进度条背景图片,设置该图片的动画,绕中心点旋转,在drawable下添加progress.xml:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
        <rotate
            android:pivotX="50%"
            android:pivotY="50%"
            android:fromDegrees="0"
            android:toDegrees="360"
            android:drawable="@drawable/progress_round"
            >
        </rotate> 
   </item>
</layer-list>

 

 

抱歉!评论已关闭.