1、自定义
package com.superx.boost.clean.base;
import android.app.Dialog;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import com.superx.boost.clean.R;
/**
* author : jian11058
* time : 2021/12/31
* desc :
*/
public abstract class BaseDialog extends Dialog {
private boolean iscancelable;//点击外部是否可以dismiss
private boolean isBackCanCelable;//返回键是否可以取消dialog
private Context mContext;
private int gravity=-1;
private boolean widthIsMatch;
private boolean heightIsMatch;
public BaseDialog(Context mContext, boolean isCancelable, boolean isBackCancelable) {
super(mContext, R.style.MyDialog);//这里设置dialog的统一主题,全屏、背景透明等
this.mContext = mContext;
this.iscancelable = isCancelable;
this.isBackCanCelable=isBackCancelable;
widthIsMatch=true;
heightIsMatch=false;
}
public BaseDialog(Context mContext, boolean isCancelable, boolean isBackCancelable,int gravity,boolean widthIsMatch,boolean heightIsMatch) {
super(mContext, R.style.MyDialog);//这里设置dialog的统一主题,全屏、背景透明等
this.mContext = mContext;
this.iscancelable = isCancelable;
this.isBackCanCelable=isBackCancelable;
this.gravity=gravity;
this.widthIsMatch=widthIsMatch;
this.heightIsMatch=heightIsMatch;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(getLayoutId());//这行一定要写在前面
setCancelable(iscancelable);//点击外部不可dismiss
setCanceledOnTouchOutside(isBackCanCelable);
Window window = this.getWindow();
if (gravity==-1){
window.setGravity(Gravity.CENTER);//设置弹框对其方式
}else {
window.setGravity(gravity);//设置弹框对其方式
}
WindowManager.LayoutParams params = window.getAttributes();
if (widthIsMatch){
params.width = WindowManager.LayoutParams.MATCH_PARENT;//设置宽高模式,
}else {
params.width = WindowManager.LayoutParams.WRAP_CONTENT;//设置宽高模式,
}
if (heightIsMatch){
params.height = WindowManager.LayoutParams.MATCH_PARENT;//设置宽高模式,
}else {
params.height = WindowManager.LayoutParams.WRAP_CONTENT;//设置宽高模式,
}
window.setAttributes(params);
initView();
}
protected abstract void initView();
protected abstract int getLayoutId();
private void fullScreenImmersive(View view) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
int uiOptions = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_FULLSCREEN;
view.setSystemUiVisibility(uiOptions);
}
}
//-------------------------隐藏系统导航栏-----------------------------------
@Override
public void show() {
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
super.show();
fullScreenImmersive(getWindow().getDecorView());
this.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
}
}
2、R.style.MyDialog,在value文件夹下找到style或者themes,将下述代码加进去
<style name="MyDialog" parent="@android:style/Theme.NoTitleBar.Fullscreen">
<!-- 是否有边框 -->
<item name="android:windowFrame">@null</item>
<!--是否在悬浮Activity之上 -->
<item name="android:windowIsFloating">true</item>
<!--标题 -->
<item name="android:windowNoTitle">true</item>
<!--阴影 -->
<item name="android:windowIsTranslucent">false</item><!--半透明-->
<!-- 点外边可以消失 -->
<item name="android:windowCloseOnTouchOutside">false</item>
<item name="android:windowBackground">@color/black_00_color</item><!--背景透明-->//这里的透明色值为:#00000000
· </style>
3、重写
package com.superx.boost.clean.dialog;
import android.content.Context;
import android.view.View;
import android.widget.LinearLayout;
import com.superx.boost.clean.R;
/**
* author : jian11058
* time : 2021/12/31
* desc :
*/
public class CircleCoinDialog extends BaseDialog{
private LinearLayout layout_all;
public CircleCoinDialog(Context context, boolean isCancelable, boolean isBackCancelable) {
super(context, isCancelable, isBackCancelable);
}
@Override
protected int getLayoutId() {
return R.layout.dialog_circle_coin;
}
@Override
protected void initView() {
layout_all=findViewById(R.id.dialog_coin_layout_all);
initData();
}
private void initData() {
layout_all.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dismiss();
}
});
}
}
view的添加与显示;
1、利用layout.addview(View);
2、利用activity中的:addContentView()
videoView = LayoutInflater.from(context).inflate(R.layout.view_video_play, null);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
//设置顶部,左边布局
params.gravity = Gravity.TOP | Gravity.LEFT;
if (context instanceof Activity) {
((Activity) context).addContentView(videoView, params);
}
可自定义任意view的布局,然后进行管理隐藏或显示 ;
progress样式:
<ProgressBar
android:id="@+id/progress_bar"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:indeterminate="false"
android:indeterminateDrawable="@drawable/progress_bar_drawable_login_white" />
progress_bar_drawable_login_white(在drawable文件夹下):
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<rotate android:drawable="@mipmap/login_loading_white"
android:fromDegrees="0.0"
android:toDegrees="360.0"
android:pivotX="50.0%"
android:pivotY="50.0%" />
</item>
</layer-list>