问题描述:在横屏全屏的显示情况下,弹窗会拉起顶部的状态栏
原因分析:
1,使用的弹窗是Dialog会拉起顶部的导航栏;
解决方案:
方法一:
在显示Dialog时隐藏所有的导航栏,是在隐藏状态栏逻辑代码的下面,加上一个状态栏变化的响应处理,在把它隐藏掉。请参考特立独行的猫a的https://blog.youkuaiyun.com/yyz_1987/article/details/90444868
但这种方法用在Dialog和PopuWindow对个别机型无效,例如:一加手机,采用该方法还会弹出底部导航栏。
方法二:
将Dialog换成DialogFragment,
首先DialogFragment是基于Fragment的,生命周期和Fragment是一样的,DialogFragment像Fragment一样粘贴在Activity上,稳定性较好。下面是一个简单DialogFragment的使用范例
public class MyDialogFragment extends DialogFragment {
private TextView textView;
public MyDialogFragment () {
}
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.my_dialog, container, false);
//初始化弹窗布局的方法
this.textView = (TextView)rootView .findViewById(R.id.textView);
return rootView ;
}
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
public void onStart() {
super.onStart();
Window window = this.getDialog().getWindow();
if (window != null) {
LayoutParams attributes = window.getAttributes();
//设置弹窗显示位置
attributes.gravity = Gravity.CENTER;
//设置弹窗显示隐藏动画
attributes.windowAnimations = anim.slide_in_up_new;
window.setAttributes(attributes);
}
}
public void onResume() {
super.onResume();
}
public void onPause() {
super.onPause();
}
public void onDetach() {
super.onDetach();
}
}
总结:
将Dialog换成DialogFragment,可彻底解决弹窗会拉起顶部的状态栏问题