在某個控件下面顯示彈窗
private void showPopupWindow(View view){
//加載佈局
View inflate = LayoutInflater.from(getContext()).inflate(R.layout.popupwindow_credit_add_screen, null);
//更改背景顏色
inflate.setBackgroundColor(getContext().getResources().getColor(R.color.white));
PopupWindow mPopupWindow = new PopupWindow(inflate);
TextView tvAddCustomer = inflate.findViewById(R.id.tv_add_customer);
TextView tvAdvancedScreen = inflate.findViewById(R.id.tv_advanced_screen);
//必須設置寬和高
mPopupWindow.setWidth(270);
mPopupWindow.setHeight(170);
//點擊其他地方隱藏,false爲無反應
mPopupWindow.setFocusable(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
//對他進行便宜
mPopupWindow.showAsDropDown(view,-135,20,Gravity.BOTTOM);
}
//對popupWindow進行顯示
mPopupWindow.update();
}
View傳入的是控件,要顯示在某個控件下面