0
我試圖使IME服務(屏幕鍵盤)中沒有任何活動的彈出窗口出現。當我調用popUp.showAtLocation(佈局,Gravity.CENTER,0,-100)時,我得到一個「Windowmanager $ BadTokenException:無法添加窗口 - 標記null無效。」我知道從沒有相關活動的服務中打開一個彈出窗口有點不尋常 - 這可能嗎?從IME創建PopupWindow:BadTokenException
這裏是我的代碼:
public void initiatePopupWindow()
{
try {
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.popup_layout,null);
// create a 300px width and 470px height PopupWindow
popUp = new PopupWindow(layout, 300, 470, true);
popUp.showAtLocation(layout, Gravity.CENTER, 0, -100);
Button cancelButton = (Button) layout.findViewById(R.id.popup_cancel_button);
cancelButton.setOnClickListener(inputView.cancel_button_click_listener);
} catch (Exception e) {
e.printStackTrace();
}
}
任何幫助,將不勝感激。謝謝