Android——加载中的dialog

1、自定义dialog

       java:

public class CustomProgressBar extends Dialog {

    private Context context ;
    private String progressText ;

    public CustomProgressBar(Context context) {
        super(context , R.style.dialog_theme) ;
        this.context = context ;
    }
    public CustomProgressBar(Context context, String progressText) {
        super(context, R.style.dialog_theme) ;
        this.context = context ;
        this.progressText = progressText ;
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.custom_progressbar) ;
        TextView title =  (TextView) findViewById(R.id.custom_imageview_progress_title);
        title.setText(progressText == null ? "加载数据中,请稍后..." : progressText) ;
    }
    /**
     * @see android.app.Dialog#show()
     */
    @Override
    public void show() {
        try{
            if(!isShowing()){
                super.show();
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        ImageView im =  (ImageView) findViewById(R.id.custom_imageview_progress_bar);
        im.startAnimation(AnimationUtils.loadAnimation(context, R.anim.round_loading));
    }
}
 
   xml:custom_progressbar.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:padding="15dip"
              android:gravity="center"
              android:background="@drawable/shen"
              android:orientation="vertical" >
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/custom_imageview_progress_bar"
        android:src="@drawable/diaog" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dip"
        android:id="@+id/custom_imageview_progress_title"
        android:textColor="@android:color/white"
        android:textSize="12sp"
        />
</LinearLayout>
2、在res文件夹下新建一个动画round_londing.xml
  
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
        android:duration="1000"
        android:fromDegrees="0"
        android:interpolator="@android:anim/linear_interpolator"
        android:pivotX="50%"
        android:pivotY="50%"
        android:repeatCount="infinite"
        android:toDegrees="+360">

</rotate>
3、在style里加入
   
<style name="dialog_theme">
    <item name="android:windowFrame">@null</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
    <item name="android:windowBackground">@color/transparent</item>
    <!-- 背景透明 -->
    <!-- 激活背景变暗遮罩 -->
    <item name="android:backgroundDimEnabled">true</item>
    <item name="android:backgroundDimAmount">0.6</item>
</style>

4、在要调用dialog的java中
CustomProgressBar cd;
//dialog开始调用此方法
public void createProgressBar() {
    this.createProgressBar(null);
}
//dialog中
public void createProgressBar(String text) {
    if (cd== null) {
        if (text == null) {
            cd= new CustomProgressBar(this);
        } else {
            cd= new CustomProgressBar(this, text);
        }
        cd.setCancelable(true);
    }
    if (!cd.isShowing()) {
        cd.show();
    }
}
//dialog结束调用此方法
public void disMissProgress() {
    if (cd!= null && cd.isShowing()) {
        cd.dismiss();
    }
}

5、这样就可以了测试一下吧,图片我就不贴了,自己找两张就ok;

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值