状态栏、导航栏、PopupWindow的使用
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了状态栏、导航栏、PopupWindow的使用相关的知识,希望对你有一定的参考价值。
参考技术A1.1 获取屏幕绝对高度: RealHeight
1.2 获取屏幕高度: Height
1.3 获取状态栏高度: StatusBarHeight
1.4 获取导航栏高度: NavigationbarHeight
假设出现窗口没准确出现在锚点下方,或者半透明背景没占满余下屏幕的情况,看看高度取值是否准确。
23华为Mate9导航栏遮挡PopupWindow底部布局
一、上图
二、问题描述
华为Mate9手机,UI的表现形式是底部黑色的导航栏遮挡住了PopupWindow底部重置与确认按钮的布局。
三、问题分析与解决思路
网上很多解决方法都是说设置popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);或者popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);来处理,在Android6.0操作系统以下没有问题,但是在Android7.0中,不能解决这个问题。
尝试过很多方法失败后,我将思路转到计算PopupWindow高度,通过showAtLocation()方法去显示,然后问题解决。具体代码如下:
public void initPopupWindow(Activity searchResultActivity, View bindView,
List<AllFiltrarteBean> allFiltrarteList, List<HotCityBean> hotCityList)
this.context = searchResultActivity;
this.bindView = bindView;
this.allFiltrarteList = SearchResultBiz
.getInstance()
.getAllFiltrarteList(SearchResultBiz
.getInstance()
.getSelectValueList(), allFiltrarteList);
this.priceMap = SearchResultBiz
.getInstance()
.getPriceMap();
this.goodsType = SearchResultBiz
.getInstance()
.getGoodsType();
this.hotCityName = SearchResultBiz
.getInstance()
.getHotCityName();
this.hotCityList = SearchResultBiz
.getInstance()
.getHotCityList(hotCityName, hotCityList);
this.searchResultActivity = (SearchResultActivity) searchResultActivity;
View dialogView = LayoutInflater
.from(context)
.inflate(R.layout.newgoodsfiltrate, null);
createPopupWindow(dialogView);
int statusBarHeight = getStatusBarHeight(context);
int screenHeight = ScreenUtil.getScreenHeight(context);
int popupWindowHeight = screenHeight - statusBarHeight - (int) DisplayUtil
.dip2px(context, 84);
popupWindow = new PopupWindow(dialogView, LayoutParams.MATCH_PARENT,
popupWindowHeight);
// 此处必须设置,否则点击事件无效,选择不了
popupWindow.setBackgroundDrawable(new BitmapDrawable());
// 设置显示动画
popupWindow.setAnimationStyle(R.style.PopupWindowAinmation02);
// 设置边缘点击可消失
popupWindow.setOutsideTouchable(true);
//解决在EditText中输入把popupwindow布局往上顶的问题
popupWindow.setSoftInputMode(WindowManager.LayoutParams
.SOFT_INPUT_ADJUST_PAN);
// 为了设置返回按钮关闭弹层
popupWindow.setFocusable(true);
dialogView.setOnKeyListener(new PopOnKeyListener());
popupWindow.setTouchInterceptor(new PopTouchListener());
/**
* 获取状态栏高度
*
* @param context
* @return
*/
public int getStatusBarHeight(Context context)
int result = 0;
int resourceId = context
.getResources()
.getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0)
result = context
.getResources()
.getDimensionPixelSize(resourceId);
return result;
/**
* 显示PopupWindow界面
*/
public void show()
if (this.isShowing())
return;
isClickConfirm = false;
if (null != searchResultActivity && !searchResultActivity.isFinishing())
if (null == bindView)
bindView = searchResultActivity
.getWindow()
.getDecorView();
popupWindow.showAtLocation(bindView, Gravity.BOTTOM, 0, 0);
以上是关于状态栏、导航栏、PopupWindow的使用的主要内容,如果未能解决你的问题,请参考以下文章