2015-08-13 44 views
0

我在Activity中的AlertDialog上实现了customizeKeyboard。当我单击Alertdialog上的edittext时,键盘会在对话框后面打开,并且不启用或不工作。如何让它出现在前面?CustomKeyboard隐藏在Android中的Alertdialog后面

这里是我的AlertDialog代码:

private void showSaveDraftDialog() { 
    if (!list.isEmpty()) { 
     LayoutInflater li = LayoutInflater.from(Activity_Sales_Return.this); 
     View promptsView = li.inflate(R.layout.save_draft, null); 


     AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
       Activity_Sales_Return.this); 

     // set prompts.xml to alertdialog builder 
     alertDialogBuilder.setView(promptsView); 

     final EditText userInput = (EditText) promptsView 
       .findViewById(R.id.et_alert_save_name); 
     userInput.requestFocus(); 

     userInput.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
//     getWindow().setSoftInputMode(
//        
WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); 
       InputMethodManager input = (InputMethodManager)  
getSystemService(Context.INPUT_METHOD_SERVICE); 
       input.hideSoftInputFromWindow(userInput.getWindowToken(),0); 
//     if(isCustomKeyboardVisible()){ 
//      hideCustomKeyboard(); 
//     }else{ 
     //showCustomKeyboard(v); 
     mKeyboardView.setVisibility(View.VISIBLE); 
     mKeyboardView.setEnabled(true); 

//     } 
      } 
     }); 
     userInput.setOnFocusChangeListener(new OnFocusChangeListener() { 

      @Override 
      public void onFocusChange(View v, boolean hasFocus) { 
       if (hasFocus) { 
        key.showCustomNumKeyboard(v); 

        } else { 

         hideCustomKeyboard(); 
        } 
      } 
     }); 

     // set dialog message 
     alertDialogBuilder 
       .setCancelable(false) 
       .setPositiveButton("Save", 
         new DialogInterface.OnClickListener() { 
          public void onClick(DialogInterface dialog, 
            int id) { 
           if (!userInput.getText().toString().trim() 
             .equalsIgnoreCase("")) { 
            SaleDraftDatabase saleDraftDatabase = 
new SaleDraftDatabase(
              mActivity); 
            saleDraftDatabase.open(); 
            boolean nameAvailable = 
saleDraftDatabase 
              .checkDraftNameAvailable(
                userId, userInput 
                  .getText() 
                  .toString() 
                  .trim()); 
            if (nameAvailable) { 
             boolean saveCheck = 
saleDraftDatabase 
               .createEntry(list, userId, 
                 userInput.getText() 
                   .toString() 
                   .trim()); 
             saleDraftDatabase.close(); 
             if (saveCheck) { 
              SalesReturnDatabase saleDatabase 
= new SalesReturnDatabase(
                mActivity); 
              saleDatabase.open(); 
              saleDatabase 

.deleteAllEntriesOfSingleUser(userId); 
              saleDatabase.close(); 
              list.clear(); 
              barcodeList.clear(); 
              Intent i = new Intent(
                mActivity, 

Activity_Sales_Return.class); 

i.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS 
                | 

Intent.FLAG_ACTIVITY_NEW_TASK); 
              startActivity(i); 
              finish(); 
              Toast.makeText(


Activity_Sales_Return.this, 
                userInput.getText() 
                  .toString() 
                  .trim() 
                  + " sale saved 

as draft.", 
                Toast.LENGTH_SHORT) 
                .show(); 
             } else 
              Toast.makeText(


Activity_Sales_Return.this, 
                "Some error occured", 
                Toast.LENGTH_SHORT) 
                .show(); 
            } else { 
             Toast.makeText(
               mActivity, 
               "Name already in use. Choose   

another name.", 
               Toast.LENGTH_SHORT).show(); 
            } 
           } else { 
            Toast.makeText(
              Activity_Sales_Return.this, 
              "Enter a valid name", 
              Toast.LENGTH_SHORT).show(); 
           } 
          } 
         }) 
       .setNegativeButton("Cancel", 
         new DialogInterface.OnClickListener() { 
          public void onClick(DialogInterface dialog, 
            int id) { 
           dialog.cancel(); 
          } 
         }); 
     // create alert dialog 
     AlertDialog alertDialog1 = alertDialogBuilder.create(); 
     alertDialog1.setTitle("Save Draft"); 
     alertDialog1.setIcon(R.drawable.ttt_logo); 
     alertDialog1.show(); 

    } else { 
     Toast.makeText(mActivity, "No Sale started yet !!", 
       Toast.LENGTH_SHORT).show(); 
    } 
    } 

回答

0
(1).Remove this line WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); 

    (2).Add below line in manifest => in Activity where you have define AlertDialog 

    android:windowSoftInputMode="adjustResize|adjustPan|stateHidden" 

for example: 

      <activity 
       android:name="com.example.Login" 
       android:configChanges="orientation|keyboard|screenSize|locale" 
       android:windowSoftInputMode="adjustResize|adjustPan|stateHidden" > 
      </activity>