2011-03-07 9 views
26

Estoy desarrollando una tableta con Android 2.2.Cómo detener la visualización automática del teclado digital cuando se cambia el foco (evento OnStart)

Tengo un formulario que estoy usando para instancias nuevas y editables. Cuando se puede editar, quiero evitar que el usuario edite ciertos campos. Administro esto en mi onStart -evento, configurando el txt.setFocusableInTouchMode(false). Esto fuerza el enfoque al siguiente EditText enfocable en mi forma (lo cual es genial), pero cuando se ejecuta, el teclado virtual aparece automáticamente para el EditText con el foco. ¿Alguien sabe cómo detener esto?

Aquí está el código (llamada en 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); 
} 

Respuesta

59

Tal vez esto le ayudará a:

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

que esto esté arreglado mi problema para la Xoom (Android 3.0.1). Agregué la línea anterior a mi método onCreate(). Todavía no estoy seguro de qué es una "entrada suave". –

+2

Entrada suave es el teclado en pantalla. La alternativa es un teclado físico real. –

+3

Esto no parece tener ningún efecto en Android 2.2. Tampoco lo hace SOFT_INPUT_STATE_ALWAYS_HIDDEN. – Torben

9

Nos puede ocultar la device Keybord siguiendo caminos que depende totalmente de la necesidad de 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 
     } 
    }); 

nombre de todo lo anterior ways_ también puede definir windowSoftInputMode en aplicación s manifest` file_

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

</application> 
</manifest> 

¡Espero que esto ayude a todos!

0

esta es la respuesta: En su AndroidManifest.xml añadir un atributo de la Actividad:

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

Creo que se perdió la pregunta en en su totalidad, esto no oculta el teclado –

Cuestiones relacionadas