Android popupWindow點擊某個控件在其下面顯示彈窗,例如淘寶的曬選

在某個控件下面顯示彈窗

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傳入的是控件,要顯示在某個控件下面

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章