標籤:android style blog http io color ar java sp
先看下效果:
1.String.xml 檔案,progressDialog是繼承與Dialog,先設定一下progressDialog的風格,設定背景透明色。
<style name="CustomDialog" parent="@android:style/Theme.Dialog"> <item name="android:windowFrame">@null</item> <item name="android:windowIsFloating">true</item> <item name="android:windowContentOverlay">@null</item> <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item> <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item> </style> <style name="CustomProgressDialog" parent="@style/CustomDialog"> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowNoTitle">true</item> </style>
2.customprogressdialog.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:orientation="horizontal"> <ImageView android:id="@+id/loadingImageView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@anim/progress_round"/> <TextView android:id="@+id/id_tv_loadingmsg" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:textSize="20dp"/> </LinearLayout>
3.progress_round.xml檔案.這個檔案為了實現轉動的效果,迴圈顯示這些圖片。
<?xml version="1.0" encoding="utf-8"?> <animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false"> <item android:drawable="@drawable/progress_1" android:duration="200"/> <item android:drawable="@drawable/progress_2" android:duration="200"/> <item android:drawable="@drawable/progress_3" android:duration="200"/> <item android:drawable="@drawable/progress_4" android:duration="200"/> <item android:drawable="@drawable/progress_5" android:duration="200"/> <item android:drawable="@drawable/progress_6" android:duration="200"/> <item android:drawable="@drawable/progress_7" android:duration="200"/> <item android:drawable="@drawable/progress_8" android:duration="200"/> </animation-list>
4.CustomProgressDialog.java檔案
package com.lxd.widgets; import com.lxd.activity.R; import android.app.Dialog;import android.content.Context;import android.graphics.drawable.AnimationDrawable;import android.view.Gravity;import android.widget.ImageView;import android.widget.TextView; /******************************************************************** * [Summary] * TODO 請在此處簡要描述此類所實現的功能。因為這項注釋主要是為了在IDE環境中產生tip協助,務必簡明扼要 * [Remarks] * TODO 請在此處詳細描述類的功能、調用方法、注意事項、以及與其它類的關係. *******************************************************************/ public class CustomProgressDialog extends Dialog { private Context context = null; private static CustomProgressDialog customProgressDialog = null; public CustomProgressDialog(Context context){ super(context); this.context = context; } public CustomProgressDialog(Context context, int theme) { super(context, theme); } public static CustomProgressDialog createDialog(Context context){ customProgressDialog = new CustomProgressDialog(context,R.style.CustomProgressDialog); customProgressDialog.setContentView(R.layout.customprogressdialog); customProgressDialog.getWindow().getAttributes().gravity = Gravity.CENTER; return customProgressDialog; } public void onWindowFocusChanged(boolean hasFocus){ if (customProgressDialog == null){ return; } ImageView imageView = (ImageView) customProgressDialog.findViewById(R.id.loadingImageView); AnimationDrawable animationDrawable = (AnimationDrawable) imageView.getBackground(); animationDrawable.start(); } /** * * [Summary] * setTitile 標題 * @param strTitle * @return * */ public CustomProgressDialog setTitile(String strTitle){ return customProgressDialog; } /** * * [Summary] * setMessage 提示內容 * @param strMessage * @return * */ public CustomProgressDialog setMessage(String strMessage){ TextView tvMsg = (TextView)customProgressDialog.findViewById(R.id.id_tv_loadingmsg); if (tvMsg != null){ tvMsg.setText(strMessage); } return customProgressDialog; }}
5.調用
CustomProgressDialog progressDialog = CustomProgressDialog.createDialog(this);
Android 自訂progressDialog實現