LoadingDialog

package com.changim.patient.app.ui.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import com.changim.patient.app.R;

/**
 * Created by zzw on 2016/6/24.
 * 描述:
 */
public class LoadDialog extends Dialog {

    private Activity context;

    private View contentView;
    private TextView hintTextView;


    private LoadDialog(Activity context, int theme) {
        super(context, theme);
        this.context = context;
        initView(context);
    }

    public LoadDialog(Activity context) {
        this(context, R.style.dialog_loading);
    }

    private void initView(Activity context) {
        contentView = LayoutInflater.from(context).inflate(R.layout.layout_progress, null);
        hintTextView = (TextView) contentView.findViewById(R.id.pro_text);
        setContentView(contentView);
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        WindowManager.LayoutParams p = getWindow().getAttributes();
        p.width = (int) context.getResources().getDimension(R.dimen.space_180);
        p.height = (int) context.getResources().getDimension(R.dimen.space_120);
        getWindow().setAttributes(p);
        getWindow().setGravity(Gravity.CENTER);
    }


    public void setMessage(int resId) {
        if (resId == 0)
            return;
        setMessage(context.getString(resId));//默认为加载
    }

    public void setMessage(String message) {
        if (message == null)
            return;
        hintTextView.setText(message);
        hintTextView.invalidate();
    }


}

 

<style name="dialog_loading" parent="BaseDialog">
        <item name="android:backgroundDimAmount">0.6</item>
        <!-- 灰度 -->
        <item name="android:windowAnimationStyle">@style/LoadAnimation</item>
        <!-- 弹出或者进入时的动画效果 -->
    </style>

     <style name="LoadAnimation" parent="android:Animation">
        <item name="android:windowEnterAnimation">@anim/dialog_load_enter</item>
        <item name="android:windowExitAnimation">@anim/dialog_load_exit</item>
    </style>


     <style name="BaseDialog" parent="@android:style/Theme.Dialog">
        <item name="android:windowFrame">@null</item>
        <!--边框-->
        <item name="android:windowNoTitle">true</item>
        <!--无标题-->
        <item name="android:windowIsFloating">true</item>
        <!--是否浮现在activity之上-->
        <item name="android:windowContentOverlay">@null</item>
        <!-- 对话框是否有遮盖 -->
        <item name="android:windowIsTranslucent">false</item>
        <!--半透明-->
        <item name="android:windowBackground">@android:color/transparent</item>
        <!--背景透明-->
        <item name="android:backgroundDimEnabled">false</item>
        <!--背景模糊-->
    </style>
style
<?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:layout_gravity="center"
    android:background="@drawable/dialog_progress_bg"
    android:gravity="center"
    android:orientation="vertical">

    <ProgressBar
        android:id="@+id/pro_pro"
        android:layout_width="@dimen/space_60"
        android:layout_height="@dimen/space_60"
        android:layout_centerInParent="true"
        android:indeterminateBehavior="repeat"
        android:indeterminateDrawable="@drawable/progress_circle" />

    <TextView
        android:id="@+id/pro_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="@dimen/space_5"
        android:text="@string/progress_loading"
        android:textColor="@color/colorWhite" />

</LinearLayout>
layout
<?xml version="1.0" encoding="utf-8"?>
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@mipmap/ic_loading"
    android:fromDegrees="0.0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:duration="500"
    android:toDegrees="360.0">

</animated-rotate>
progress_circle

 

ic_loading :  xx:

 

posted on 2016-08-31 11:06  Z2  阅读(1236)  评论(0编辑  收藏  举报

导航