android 自定义progressDialog 之一

首先附上效果图




1、自定义dialog背景

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <!-- 边角的圆弧半径 -->
    <corners android:radius="10dp" />

    <!-- 实心填充 -->
    <solid android:color="#ff000000" />

    <!-- 描边:一般大小都是1dp -->
    <stroke
        android:width="1dp"
        android:color="#ff303030" />
</shape>
2、自定义dialog布局

<?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:orientation="vertical"
    android:background="@drawable/dialog_bg"
    android:paddingBottom="20dp"
	android:paddingLeft="30dp"
	android:paddingRight="30dp"
	android:paddingTop="20dp" >

    <ProgressBar
        android:id="@+id/progressBar1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal" />

    <TextView
        android:id="@+id/tv_dialogmsg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:text="加载中..."
        android:textColor="#ffa0a0a0"
        android:textAppearance="?android:attr/textAppearanceSmall" />

</LinearLayout>
3、重写Dialog
package com.view;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.widget.TextView;

import com.example.tzq.R;

public class MyLoadDialog extends Dialog {
	
	private Context context;
	private String text;

	public MyLoadDialog(Context context, String text) {
		super(context);
		// TODO Auto-generated constructor stub
		this.context = context;
		this.text = text;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View view = inflater.inflate(R.layout.dialog_load, null);
		setContentView(view, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
		
		//		getWindow().setBackgroundDrawable(new BitmapDrawable());
		getWindow().setBackgroundDrawableResource(android.R.color.transparent); // 去掉边角
		
		if(text != null) {
			TextView tv = (TextView) findViewById(R.id.tv_dialogmsg);
			tv.setText(text);
		}
	}
	@Override
	public void show() {
		// TODO Auto-generated method stub
		requestWindowFeature(Window.FEATURE_NO_TITLE); // 去掉标题<pre name="code" class="java">
super.show();}}

 4、在Activity中调用 

显示Dialog

MyLoadDialog loadDialog = new MyLoadDialog(LoginActivity.this, "登录中,请稍后...");
loadDialog.show();
取消Dialog
loadDialog.dismiss();




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值