[2.13.2][fix] dialog适配

This commit is contained in:
yangyakun
2023-01-10 17:50:41 +08:00
parent 98c85d9ee5
commit 3254680bd0

View File

@@ -3,16 +3,20 @@ package com.zhjt.dispatch;
import android.app.Dialog;
import android.content.Context;
import android.os.Build;
import android.view.Gravity;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.FrameLayout;
import androidx.annotation.NonNull;
import com.mogo.eagle.core.data.dispatch.DispatchAdasAutoPilotLocReceiverBean;
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger;
public abstract class DispatchBaseDialog extends Dialog {
public DispatchBaseDialog(@NonNull Context context) {
super(context,R.style.Base_AlertDialog_AppCompat);
super(context,R.style.BaseFloatDialogStyle);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
} else {
@@ -27,4 +31,22 @@ public abstract class DispatchBaseDialog extends Dialog {
public abstract void showDialog(DispatchAdasAutoPilotLocReceiverBean dispatchContent);
@Override
public void show() {
super.show();
setWindowSize();
}
private void setWindowSize(){
WindowManager.LayoutParams attributes = getWindow().getAttributes();
attributes.width = ViewGroup.LayoutParams.MATCH_PARENT;
attributes.height = ViewGroup.LayoutParams.MATCH_PARENT;
FrameLayout content = (FrameLayout)findViewById(android.R.id.content);
if(content!=null){
ViewGroup rootView = (ViewGroup) content.getChildAt(0);
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) rootView.getLayoutParams();
layoutParams.gravity = Gravity.CENTER;
rootView.setLayoutParams(layoutParams);
}
getWindow().setAttributes(attributes);
}
}