2011-03-07 22 views
26

Sto sviluppando per un tablet con Android 2.2.Come interrompere la visualizzazione della tastiera software quando viene modificata la messa a fuoco (evento OnStart)

Ho un modulo che sto usando per istanze nuove e modificabili. Quando modificabile, voglio impedire all'utente di modificare determinati campi. Lo gestisco nel mio onStart -event, impostando lo txt.setFocusableInTouchMode(false). Questo impone il focus sulla successiva messa a fuoco EditText nel mio modulo (che è ottimo), ma quando è in esecuzione, la tastiera virtuale viene automaticamente visualizzata per lo EditText con lo stato attivo. Qualcuno sa come fermarlo?

Ecco il codice (chiamato in caso onStart):

private void PopulateFields(){ 
    TextView txtTitle = (TextView) this.findViewById(R.id.txtEquipmentEditTitle); 
    AutoCompleteTextView txtMake = (AutoCompleteTextView) this.findViewById(R.id.autEquipmentEditMake); 
    AutoCompleteTextView txtModel = (AutoCompleteTextView) this.findViewById(R.id.autEquipmentEditModel); 
    EditText txtDesc = (EditText) this.findViewById(R.id.txtEquipmentEditDesc); 
    TextView txtDeptKey = (TextView) this.findViewById(R.id.txtEquipmentEditDeptKey); 
    EditText txtSerial = (EditText) this.findViewById(R.id.txtEquipmentEditSerialNo); 
    EditText txtBarCode = (EditText) this.findViewById(R.id.txtEquipmentEditBarCode); 

    txtTitle.setText("Edit Equipment"); 
    txtMake.setText(make); 
    txtModel.setText(model); 
    txtDesc.setText(desc); 
    txtDeptKey.setText(Integer.toString(deptKey)); 
    txtSerial.setText(serial); 
    txtBarCode.setText(barCode); 
    txtMake.setEnabled(false); 
    txtModel.setEnabled(false); 
    txtDesc.setEnabled(false); 
    txtMake.setClickable(false); 
    txtMake.setFocusableInTouchMode(false); 
    txtModel.setFocusableInTouchMode(false); 
    txtDesc.setFocusableInTouchMode(false); 
    txtMake.setFocusable(false); 
    txtModel.setFocusable(false); 
    txtDesc.setFocusable(false); 
} 

risposta

59

Forse questo ti aiuterà a:

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); 
+0

Questo fissa il mio problema per il xoom (Android 3.0.1). Ho aggiunto la riga sopra al mio metodo onCreate(). Non sono ancora sicuro di cosa sia un "input morbido". –

+2

L'input graduale è la tastiera su schermo. L'alternativa è una vera tastiera fisica. –

+3

Questo non sembra avere alcun effetto su Android 2.2. Né SOFT_INPUT_STATE_ALWAYS_HIDDEN. – Torben

9

possiamo nascondere il device Keybord dai seguenti sensi, che dipende totalmente sulla necessità di situation_

First Way_

EditText userId; 
    /* 
    * When you want that Keybord not shown untill user clicks on one of the EditText Field. 
    */ 
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); 

Second Way_ InputMethodManager

/* 
    * When you want to use service of 'InputMethodManager' to hide/show keyboard 
    */ 
    InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 

    inputManager.hideSoftInputFromWindow(userId.getWindowToken(), 
      InputMethodManager.HIDE_NOT_ALWAYS); 

Third Way_

/* 
    * Touch event Listener 
    * When you not want to open Device Keybord even when user clicks on concern EditText Field. 
    */ 
    userId.setOnTouchListener(new OnTouchListener(){ 
     @Override 
     public boolean onTouch(View v, MotionEvent event) { 
      int inType = userId.getInputType(); // backup the input type 
      userId.setInputType(InputType.TYPE_NULL); // disable soft input 
      userId.onTouchEvent(event); // call native handler 
      userId.setInputType(inType); // restore input type 
      userId.setFocusable(true); 
      return true; // consume touch even 
     } 
    }); 

Per conto di tutto quanto sopra ways_ è anche possibile definire windowSoftInputMode in applicazione s manifest` file_

<manifest ... > 
<application ... > 
    <activity 
     android:windowSoftInputMode="stateHidden|stateAlwaysHidden" 
     ... > 
     <intent-filter> 
      ... 
     </intent-filter> 
    </activity> 

</application> 
</manifest> 

Spero che questo possa aiutare tutti!

0

questa è la risposta: Nel vostro AndroidManifest.xml aggiungere un attributo alla attività:

 <activity android:name=".MyActivity" android:windowSoftInputMode="adjustPan"> </activity> 
+0

Penso che tu abbia perso la domanda in per intero, questo non nasconde la tastiera –

Problemi correlati