2015-10-04 103 views
1

我彈出了按鈕和編輯文本。然後我觸摸編輯文字或使用彈出窗口崩潰如果顯示軟鍵盤

InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); 
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);keyboard 

應用程序崩潰。

錯誤是: java.lang.IllegalArgumentException:添加窗口後無法更改窗口類型。

代碼:

LayoutInflater layoutInflater = (LayoutInflater) getActivity().getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
View popupView = layoutInflater.inflate(R.layout.popup_over_map, null); 
          Context context = this.getActivity().getApplicationContext(); 
          WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); 
          DisplayMetrics metrics = new DisplayMetrics(); 
          wm.getDefaultDisplay().getMetrics(metrics); 
          int displayWidth = metrics.widthPixels; 
          int displayHeight = metrics.heightPixels; 
          WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(displayWidth - 10, displayHeight - 125); 
          layoutParams.gravity = Gravity.CENTER_HORIZONTAL; 
          final PopupWindow popupWindow = new PopupWindow(popupView, 
     layoutParams.width, layoutParams.height, true); 
     popupWindow.setSoftInputMode(WindowManager.LayoutParams. 
     SOFT_INPUT_STATE_VISIBLE); 

          Button btnDismiss = (Button) popupView.findViewById(R.id.close_window_btn); 
          btnDismiss.setOnClickListener(this); 

          etTimeUntil = (EditText)popupView.findViewById(R.id.time_et); 

          checkOnDemand = (CheckBox) popupView.findViewById(R.id.check_ondemand_popup); 
      .... 

回答

3

請檢查您的清單,作爲目標的版本應小於14或刪除針對性的版本標記....!

<uses-sdk 
    android:targetSdkVersion="11"/> 

我也在這個問題上遇到過這是對我有用的東西祝您好運...!

+0

它幫助我!但屏幕變成黑色...... –

+0

檢查您的PopUpView配置...! –