1

私はJavaコードで設定したいEditTextので、クリックするとCursorAndroid標準キーボードは表示されず、表示されます。これどうやってするの?ありがとう

私は編集しました:

私は EditText の配列を持っています:

for (i=0;i<N*N;i++) {
    value[i].setOnTouchListener(this);
    value[i].setOnClickListener(this);
    value[i].setOnFocusChangeListener(this);
}

そしてこの方法:

@Override
public void onClick(View v) {
    for (i =0 ; i < N*N; i++) {

        if(v == value[i]) {
        variable = 1;
        if(jey!=i) {
            jey=i;
            showDialog(CUSTOM_DIALOG);
            }
        }
    }
}

@Override
public void onTouch(View v, MotionEvent event) {
    for (i =0 ; i < N*N; i++) {

        if(v == value[i]) {
        variable = 1;
        if(jey!=i) {
            jey=i;
            showDialog(CUSTOM_DIALOG);
            }
        }
    }
}

@Override
public void onFocusChange(View v, boolean hasFocus) { 
    for (i =0 ; i < N*N; i++){
        if(v == value[i]) {
            variable =1;
            if(jey!=i) {
                jey=i;
                imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(value[jey].getWindowToken(), 0);
            }
        }
    }
}

しかし、この方法では機能しません。標準のキーボードがまだ表示されます

4

6 に答える 6

0

どうぞ。

/**
 * EditText which suppresses IME show up.
 */
public class DigitsEditText extends EditText {
    public DigitsEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
        setInputType(getInputType() | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
    }

    @Override
    protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
        super.onFocusChanged(focused, direction, previouslyFocusedRect);
        final InputMethodManager imm = ((InputMethodManager) getContext()
                .getSystemService(Context.INPUT_METHOD_SERVICE));
        if (imm != null && imm.isActive(this)) {
            imm.hideSoftInputFromWindow(getApplicationWindowToken(), 0);
        }
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        final boolean ret = super.onTouchEvent(event);
        // Must be done after super.onTouchEvent()
        final InputMethodManager imm = ((InputMethodManager) getContext()
                .getSystemService(Context.INPUT_METHOD_SERVICE));
        if (imm != null && imm.isActive(this)) {
            imm.hideSoftInputFromWindow(getApplicationWindowToken(), 0);
        }
        return ret;
    }

    @Override
    public void sendAccessibilityEventUnchecked(AccessibilityEvent event) {
        if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED) {
            // Since we're replacing the text every time we add or remove a
            // character, only read the difference. (issue 5337550)
            final int added = event.getAddedCount();
            final int removed = event.getRemovedCount();
            final int length = event.getBeforeText().length();
            if (added > removed) {
                event.setRemovedCount(0);
                event.setAddedCount(1);
                event.setFromIndex(length);
            } else if (removed > added) {
                event.setRemovedCount(1);
                event.setAddedCount(0);
                event.setFromIndex(length - 1);
            } else {
                return;
            }
        } else if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED) {
            // The parent EditText class lets tts read "edit box" when this View has a focus, which
            // confuses users on app launch (issue 5275935).
            return;
        }
        super.sendAccessibilityEventUnchecked(event);
    }
}
于 2012-12-19T19:25:17.213 に答える
0

ここで@Lupsaaからの最良の解決策:

フラグ textIsSelectable を true に設定すると、ソフト キーボードが無効になります。

次のように xml レイアウトで設定できます。

<EditText
android:id="@+id/editText"
...
android:textIsSelectable="true"/>

または、プログラムで次のようにします。

EditText editText = (EditText) findViewById(R.id.editText);

editText.setTextIsSelectable(真);

カーソルは引き続き表示され、選択/コピー/切り取り/貼り付けはできますが、ソフト キーボードは表示されません。

于 2015-04-08T08:22:25.497 に答える
0

またはこれを使用します:

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

編集:

これは、他のスレッドで見つけた一般的な解決策です。

public class NoImeEditText extends EditText {

     public NoImeEditText(Context context, AttributeSet attrs) { 
          super(context, attrs);     
     }  

     @Override      
     public boolean onCheckIsTextEditor() {   
          return false;     
     }        
} 

これは私の 3 回目の試行であり、私は馬鹿げていると感じ始めているので、今回は個人的にテストしましたが、うまくいきました。レイアウトで型を使用する場合は、型も変更することを忘れないでください。

于 2012-08-14T10:54:46.387 に答える
0

1 つの EditText に適用するには (Activity ではなく、他の回答を伝える方法)、focusChangeListener に非表示を指定するだけです。

mEditText.setOnFocusChangeListener(new CustomListener());

および CustomListener:

protected class CustomListener implements View.OnFocusChangeListener {
    @Override
    public void onFocusChange(View v, boolean hasFocus) {
        InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
    }
}

hasFocustrue の場合のみ、チェックして非表示にすることができます。

于 2012-08-14T10:59:24.300 に答える
-1
add android:configChanges="keyboardHidden" in manifestfile to the activity
于 2012-08-14T10:52:37.457 に答える