首先我们自定义style
<style name="CustomProgressDialog" parent="@style/CustomDialog">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
android:windowBackground这个属性就是用来设置window的背景,这里用系统自带的透明就行了
自定义控件代码
package com.cattsoft.deliersystem.view;
import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.cattsoft.deliersystem.R;
public class ProgressDialog extends Dialog {
private Context context = null;
private static ProgressDialog customProgressDialog = null;
public ProgressDialog(Context context) {
super(context);
this.context = context;
}
public ProgressDialog(Context context, int theme) {
super(context, theme);
}
public static ProgressDialog createDialog(Context context) {
customProgressDialog = new ProgressDialog(context,
R.style.CustomProgressDialog);
//设置自定义的视图
customProgressDialog.setContentView(R.layout.dialog_view);
//设置ProgressBar在window上显示的位置
customProgressDialog.getWindow().getAttributes().gravity = Gravity.BOTTOM;
LayoutParams params = customProgressDialog.getWindow().getAttributes();
params.y = 370;
customProgressDialog.getWindow().setAttributes(params);
customProgressDialog.show();
return customProgressDialog;
}
public void onWindowFocusChanged(boolean hasFocus) {
if (customProgressDialog == null) {
return;
}
}
/**
*
* setTitile 标题
*
* @param strTitle
* @return
*
*/
public ProgressDialog setTitile(String strTitle) {
return customProgressDialog;
}
/**
* 设置ProgressBar是否显示
*
* @param bool
*/
public void setProgressBar(boolean bool) {
ProgressBar progressBar = (ProgressBar) customProgressDialog
.findViewById(R.id.progress);
if (bool) {
progressBar.setVisibility(View.VISIBLE);
} else {
progressBar.setVisibility(View.GONE);
}
}
/**
*
* [setMessage 提示内容
*
* @param strMessage
* @return
*
*/
public ProgressDialog setMessage(String strMessage) {
TextView tvMsg = (TextView) customProgressDialog
.findViewById(R.id.id_tv_loadingmsg);
if (tvMsg != null) {
tvMsg.setText(strMessage);
}
return customProgressDialog;
}
}
自定义进度对话框实现
本文介绍了如何在Android中自定义进度对话框样式,并通过代码实现了背景透明、无标题栏和关闭按钮的功能。
503

被折叠的 条评论
为什么被折叠?



