做项目的时候,直接用到了一个ProgressDialog,需要实现全屏的效果,如下图所示,功能跑起来的时候发现不是全屏,只是包裹了当前的内容,如下图所示,不过查找一些资料,把问题解决了。
本文的知识点:
1、实现ProgressDialog的全屏效果
2、接口回调推荐的方式
项目要求实现的效果.png
刚开始实现的效果.png
代码实现:
1、布局
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
android:id="@+id/iv_load_anim"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/anim_all_load"/>
android:id="@+id/tv_all_load"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/tip_load_pay_wait_result"
android:textSize="26sp"
android:textColor="@color/c_white"
android:layout_marginTop="20dp"/>
android:id="@+id/tv_all_load_other"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/tip_load_pay_wait_tip"
android:textSize="26sp"
android:textColor="@color/c_orange_1"
android:layout_marginTop="20dp"/>
android:id="@+id/btn_cancel"
android:layout_height="75dp"
android:layout_width="600dp"
android:layout_marginTop="20dp"
android:text="取消查询"
android:background="@drawable/btn_white_gray7_selector"
android:textColor="#000000"
android:textSize="30sp" />
2、核心代码
Window window = getWindow();
WindowManager.LayoutParams layoutParams = window.getAttributes();
layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
layoutParams.height = WindowManager.LayoutParams.MATCH_PARENT;
layoutParams.gravity = gravity;
window.setAttributes(layoutParams);
3、接口回调的实现方式
public OnClickCancelListener mOnClickCancelListener;
public void setOnClickCancelListener(OnClickCancelListener onClickCancelListener){
this.mOnClickCancelListener = onClickCancelListener;
}
public interface OnClickCancelListener{
void singleClick();
}
4、接口回调的调用方式
mLoadingProgressDialog.setOnClickCancelListener(new LoadingProgressDialog.OnClickCancelListener() {
@Override
public void singleClick() {
LogUtil.d(TAG,"点击取消查询===========");
isContinueQuery = true;
dismissPayResultLoadingDialog();
}
});
5、全部代码实现
public class LoadingProgressDialog extends ProgressDialog {
private static final String TAG = LoadingProgressDialog.class.getSimpleName();
public LoadingProgressDialog(Context context) {
super(context,R.style.style_custon_dialog);
setCancelable(false);
setCanceledOnTouchOutside(false);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.custom_dialog_all_loading);
Window window = getWindow();
WindowManager.LayoutParams layoutParams = window.getAttributes();
layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
layoutParams.height = WindowManager.LayoutParams.MATCH_PARENT;
layoutParams.gravity = gravity;
window.setAttributes(layoutParams);
Button benCancel = (Button) findViewById(R.id.btn_cancel);
benCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LogUtil.d(TAG,"benCancel================");
mOnClickCancelListener.singleClick();
}
});
}
public OnClickCancelListener mOnClickCancelListener;
public void setOnClickCancelListener(OnClickCancelListener onClickCancelListener){
this.mOnClickCancelListener = onClickCancelListener;
}
public interface OnClickCancelListener{
void singleClick();
}
}