Подтвердить что ты не робот

Как остановить мягкую клавиатуру, автоматически отображаемую при изменении фокуса (событие OnStart)

Я разрабатываю планшет с Android 2.2.

У меня есть форма, которую я использую для новых и редактируемых экземпляров. Когда редактируется, я хочу, чтобы пользователь не редактировал определенные поля. Я управляю этим в своем onStart -event, устанавливая txt.setFocusableInTouchMode(false). Это заставляет фокус к следующему фокусируемому EditText в моей форме (что отлично), но при работе мягкая клавиатура автоматически появляется для EditText с фокусом. Кто-нибудь знает, как остановить это?

Здесь код (вызываемый в событии 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);
}
4b9b3361

Ответ 1

Возможно, это поможет вам:

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

Ответ 2

Мы можем скрыть device Keybord следующими способами, которые полностью зависят от необходимости ситуации _

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
        }
    });

От имени всех вышеперечисленных способов вы также можете определить windowSoftInputMode в приложении s manifest` file _

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

 </application>
</manifest>

Надеюсь, это поможет всем!

Ответ 3

это ответ: В AndroidManifest.xml добавьте атрибут Activity:

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