91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

自定義ProgressDialog

發布時間:2020-07-09 23:14:37 來源:網絡 閱讀:663 作者:鷺島猥瑣男 欄目:移動開發

最近工作中需要用到progressDialog,可是系統自帶的黑色progressDialog又是其丑無比,無奈只能自己自定義了,在網上查看別人的例子,并自己整理了一份Demo:

先上圖:

自定義ProgressDialog

自定義ProgressDialog


MyProgressDialog:


package com.example.myprogressdialog_zzw;

import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.view.Gravity;
import android.view.View;
import android.view.animation.Animation;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * @author 鷺島猥瑣男
 *
 */
public class MyProgressDialog extends Dialog
{
    private Context context;
    private static MyProgressDialog myProgressDialog = null;

    public MyProgressDialog(Context context)
    {
        super(context);
        this.context = context;
    }

    public MyProgressDialog(Context context, int theme)
    {
        super(context, theme);
    }

    public static MyProgressDialog createDialog(Context context)
    {
        myProgressDialog = new MyProgressDialog(context,
                R.style.myprogressDialog);
        myProgressDialog.setContentView(R.layout.dialog_layout);
        myProgressDialog.getWindow().getAttributes().gravity = Gravity.CENTER;
        return myProgressDialog;

    }

    /*
     * (non-Javadoc)
     *
     * @see android.app.Dialog#onWindowFocusChanged(boolean) 設置動畫
     */
    @Override
    public void onWindowFocusChanged(boolean hasFocus)
    {
        // TODO Auto-generated method stub
        super.onWindowFocusChanged(hasFocus);
        ImageView p_w_picpath_loadingp_w_picpath = (ImageView) myProgressDialog
                .findViewById(R.id.p_w_picpath_loadingp_w_picpath);
        AnimationDrawable animation = (AnimationDrawable) p_w_picpath_loadingp_w_picpath
                .getBackground();
        animation.start();
    }

    public MyProgressDialog setTitle(String strTitle)
    {
        return myProgressDialog;
    }

    /**
     * @param strMessage
     * @return 設置progressDialog的消息內容
     */
    public MyProgressDialog setMessage(String strMessage)
    {
        TextView tv_loadingmsg = (TextView) myProgressDialog
                .findViewById(R.id.tv_loadingmsg);
        if (tv_loadingmsg != null)
        {
            tv_loadingmsg.setText(strMessage);
        }
        return myProgressDialog;
    }
}



在MainActivity中對MyProgressDialog進行調用,為了模仿網絡訪問結束后,關閉ProgressDialog的過程,采用了線程的sleep,運行5秒后關閉ProgressDialog,上代碼:


package com.example.myprogressdialog_zzw;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

/**
 * @author 鷺島猥瑣男
 * 采用線程的的sleep模擬下載結束后關閉progressDialog
 *
 */
public class MainActivity extends Activity
{
    MyProgressDialog myProgressDialog = null;
    Handler handler = new Handler()
    {
        public void handleMessage(Message msg)
        {
            if (msg.what == 1)
            {
                Log.e("接收到消息", "" + msg.what);
                if (myProgressDialog != null)
                {
                    myProgressDialog.dismiss();
                    myProgressDialog = null;
                }
                Toast.makeText(MainActivity.this, "加載完成!", Toast.LENGTH_SHORT)
                        .show();
            }
        };
    };

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button btn_go = (Button) findViewById(R.id.button1);
        btn_go.setOnClickListener(new OnClickListener()
        {

            @Override
            public void onClick(View v)
            {
                if (myProgressDialog == null)
                {
                    myProgressDialog = MyProgressDialog
                            .createDialog(MainActivity.this);
                    myProgressDialog.setMessage("努力加載中...");

                }
                myProgressDialog.show();
                new Thread()
                {
                    @Override
                    public void run()
                    {
                        Log.e("線程", "進入線程!");
                        try
                        {
                            Thread.sleep(5000);
                            Message msg = new Message();
                            msg.what = 1;
                            handler.sendMessage(msg);
                        }
                        catch (InterruptedException e)
                        {
                            Log.e("異常", "失敗!異常");
                        }

                    }
                }.start();

            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}


下載地址:http://download.csdn.net/detail/zzw0221/7609051

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

巨鹿县| 醴陵市| 满城县| 都兰县| 南雄市| 紫阳县| 从化市| 哈密市| 鞍山市| 寿光市| 柘荣县| 白玉县| 搜索| 金溪县| 惠安县| 新化县| 闻喜县| 壶关县| 阳江市| 昭觉县| SHOW| 西吉县| 县级市| 彭州市| 永新县| 东明县| 黑河市| 留坝县| 宝清县| 中牟县| 莱芜市| 镇雄县| 鄂尔多斯市| 锡林浩特市| 曲松县| 泾阳县| 乐东| 星座| 南汇区| 卫辉市| 永安市|