自定义Dialog之Progress(二)
系统的Dialog一般是适合UI设计的需求,那么就需要自定义的ProgressDialog.
第一想法就是能在应用级别全局改变应用的ProgressDialog的样式。(已经试过,没有成功)做法是:
<item name="android:progressBarStyle">@style/theme.customer_progress_dialog</item>
@style/theme.customer_progress_dialog 是自定义的theme
如果有成功的,希望能分享下,谢谢。
第二种做法是自定义theme, 然后定义一个ProgressDialog:CustomProgressDialog. 在应用里面就用这个.
自定义theme:
<style name="theme.customer_progress_dialog" parent="@android:style/Theme.Dialog"> <item name="android:alertDialogStyle">@style/customer_progress_dialog</item> <item name="android:progressBarStyleSmall">@style/customer_progress_dialog</item> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowNoTitle">true</item> <item name="android:windowIsTranslucent">true</item> <item name="android:paddingLeft">10dip</item> //图片与左边距的距离 <item name="android:paddingRight">10dip</item> //message与右边距的距离 <item name="android:textSize">20sp</item> //message字体的大小 <item name="android:textColor">@android:color/white</item> //message字体的颜色 </style>
@style/customer_progress_dialog 自定义的ProgressDialog style
<style name="customer_progress_dialog" parent="@android:style/Widget.ProgressBar"> <item name="android:indeterminateDuration">2000</item> <item name="android:fullDark">@drawable/tip2_bg</item> <item name="android:topDark">@drawable/tip2_bg</item> <item name="android:centerDark">@drawable/tip2_bg</item> <item name="android:bottomDark">@drawable/tip2_bg</item> <item name="android:fullBright">@drawable/tip2_bg</item> <item name="android:topBright">@drawable/tip2_bg</item> <item name="android:centerBright">@drawable/tip2_bg</item> <item name="android:bottomBright">@drawable/tip2_bg</item> <item name="android:bottomMedium">@drawable/tip2_bg</item> <item name="android:centerMedium">@drawable/tip2_bg</item> </style>
自定义的CustomProgressDialog:
package com.example.android; import android.app.ProgressDialog; import android.content.Context; import android.os.Bundle; public class CustomeProgressDialog extends ProgressDialog { private Context mContent ; public CustomeProgressDialog(Context context){ super(context,R.style.theme_customer_progress_dialog) ; mContent = context ; } public CustomeProgressDialog(Context context, int theme) { super(context, theme); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setIndeterminateDrawable(mContent.getResources().getDrawable(R.drawable.customer_progess_dialog)) ; this.setCanceledOnTouchOutside(false) ; } public static CustomeProgressDialog show(Context context,String message){ CustomeProgressDialog dialog = new CustomeProgressDialog(context) ; dialog.setMessage(message) ; dialog.show() ; return dialog ; } }
测试代码:
CustomeProgressDialog.show(this,"上传数据中") ;
结果: