1、判断是否是主线程
Looper.getMainLooper().getThread() == Thread.currentThread()
2、PopupWindow使用问题
在Android7.0上面如果使用如下方式会出现调用showAsDropDown方法PopupWindow顶到状态栏下方,而不是在指定View下方的现象,解决办法计算PopupWindow到屏幕底部实际需要的高度,不用MATCH_PARENT。
不合适
final PopupWindow window = new PopupWindow(view, FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT, true);
final PopupWindow window = new PopupWindow(view, FrameLayout.LayoutParams.MATCH_PARENT, getResources().getDisplayMetrics().heightPixels - xy - mTimeFilterView.getHeight(), true);
private void showDateSelectDialog(View view, final FilterView floatFilterView) {
int[] location = new int[2];
mTimeFilterView.getLocationOnScreen(location);
int y = location[1];
int height = ScreenUtils.getScreenHeight(mActivity) - y - mTimeFilterView.getHeight();
final PopupWindow window = new PopupWindow(view, FrameLayout.LayoutParams.MATCH_PARENT, height, true);
// 设置PopupWindow的背景
window.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#30000000")));
// 设置PopupWindow是否能响应外部点击事件
window.setOutsideTouchable(true);
// 设置PopupWindow是否能响应点击事件
window.setTouchable(true);
window.getContentView().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
window.dismiss();
}
});
window.setOnDismissListener(new PopupWindow.OnDismissListener() {
@Override
public void onDismiss() {
floatFilterView.setOpened(false);
}
});
PopupWindowCompat.showAsDropDown(window, mTimeFilterView, Gravity.BOTTOM, 0, 0);
}
3、BottomNavigationView设置图片、文字颜色不被改变
BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
navigation.setItemIconTintList(null);
navigation.setItemTextColor(getResources().getColorStateList(R.drawable.app_item_text_color));//color selector
或者使用库:
https://github.com/ittianyu/BottomNavigationViewEx