27

Android2.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);
}
4

4 に答える 4

65

多分これはあなたを助けるでしょう:

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

このメソッドは、アクティビティが最初に作成または呼び出されたときのonCreate()メソッドに入れてください。activity

于 2011-03-30T09:46:46.783 に答える
13

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 ... >
 <application ... >
    <activity 
        android:windowSoftInputMode="stateHidden|stateAlwaysHidden"
        ... >
        <intent-filter>
           ...
        </intent-filter>
    </activity>

 </application>
</manifest>

これがすべてに役立つことを願っています!

于 2013-10-25T09:24:19.703 に答える
-1

これが答えです: AndroidManifest.xml で、アクティビティに属性を追加します。

        <activity android:name=".MyActivity" android:windowSoftInputMode="adjustPan"> </activity>
于 2015-01-29T20:08:15.027 に答える