2

アプリに があり、EditTextキーを入力する代わりに ime ボタンを表示し、長すぎるテキストを次の行に移動する (SMS アプリのように) 2 行にしたい。今のところ、私は次のようなものを持っています:

<AutoCompleteTextView
    android:id="@+id/name_field"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_marginLeft="10dp"
    android:layout_weight="1"
    android:background="@null"
    android:freezesText="true"
    android:hint="@string/some_hint"
    android:imeOptions="actionNext"
    android:maxLength="100"
    android:nextFocusDown="@null"
    android:lines="2"
    android:ellipsize="end"
    android:inputType="textImeMultiLine"
    android:selectAllOnFocus="true"
    android:textColor="@android:color/black"
    android:textSize="16sp" />

最初に言及した 2 つのプロパティがありますが、3 番目に到達できるオプションを思い出すことができません。

例: my の 1 行にEditText10 文字がある場合、次のように "abc abcd abc abcdefghijk" というテキストを表示したい:

abc abcd
abc abc...

編集:問題があるようですandroid:inputType="textImeMultiLine"。すべてに変更するとandroid:inputType="textMultiLine"正常に動作しますが... IMEボタンの代わりに入力ボタンがあり、避けたいです。

4

4 に答える 4

1

これを試してみてください..うまくいくことを願っています!

<AutoCompleteTextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_marginLeft="10dp"
    android:background="@null"
    android:freezesText="true"
    android:imeOptions="actionNext"
    android:maxLength="100"
    android:nextFocusDown="@null"
    android:lines="2"
    android:ellipsize="end"
    android:selectAllOnFocus="true"
    android:textColor="@android:color/black"
    android:textSize="16sp" />
于 2013-08-21T12:05:58.487 に答える
0

これらの方法はどれもうまくいきませんでした。約 1 時間グーグルで調べたところ、次のコードが見つかりました。

EditText editText = findViewById(R.id.editNote);
    editText.setRawInputType(InputType.TYPE_CLASS_TEXT);
    editText.setImeActionLabel("DONE",EditorInfo.IME_ACTION_DONE);              //Set Return Carriage as "DONE"
    editText.setImeOptions(EditorInfo.IME_ACTION_DONE);

    editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
        {
            if (event == null) {
                if (actionId == EditorInfo.IME_ACTION_DONE) {
                    // Capture soft enters in a singleLine EditText that is the last EditText
                    // This one is useful for the new list case, when there are no existing ListItems
                    editText.clearFocus();
                    InputMethodManager inputMethodManager = (InputMethodManager)getSystemService(Activity.INPUT_METHOD_SERVICE);
                    inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
                }

                else if (actionId == EditorInfo.IME_ACTION_NEXT) {
                    // Capture soft enters in other singleLine EditTexts
                } else if (actionId == EditorInfo.IME_ACTION_GO) {
                } else {
                    // Let the system handle all other null KeyEvents
                    return false;
                }
            }
            else if (actionId == EditorInfo.IME_NULL) {
                // Capture most soft enters in multi-line EditTexts and all hard enters;
                // They supply a zero actionId and a valid keyEvent rather than
                // a non-zero actionId and a null event like the previous cases.
                if (event.getAction() == KeyEvent.ACTION_DOWN) {
                    // We capture the event when the key is first pressed.
                } else {
                    // We consume the event when the key is released.
                    return true;
                }
            }
            else {
                // We let the system handle it when the listener is triggered by something that
                // wasn't an enter.
                return false;
            }
            return true;
        }
    });

EditText を次のようにしてください。

<EditText
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/editNote"
            android:hint="Start Typing..."
            android:inputType="textMultiLine"
            android:gravity="start" />

このコードをどこから入手したか覚えていないので、作者を信用できません。必要に応じて必要な変更を加えました。

于 2018-09-25T17:28:24.193 に答える
0

android:maxLines="2"代わりにこれをxmlに追加しますandroid:lines="2"

于 2013-08-21T11:49:48.497 に答える