18

以下に定義された単純なものEditTextがあります。ListView

アプリを実行すると、EditText が選択され、キーボードが表示されます。

そうなってほしくない。デフォルトで選択したり、キーボードを表示したりしたくありません。

<EditText
    android:id="@+id/search_box"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:hint="type to search titles"
    android:inputType="text"
    android:maxLines="1"
    android:capitalize="none"
    android:linksClickable="false"
    android:autoLink="none"
    android:autoText="true"
    android:singleLine="true" />
<ListView
    android:id="@+id/DetailsListView"
    android:layout_width="fill_parent"
    android:layout_height="0dip"
    android:layout_weight="1"
    android:background="@color/transparent"
    android:cacheColorHint="@color/transparent"
    android:listSelector="@drawable/list_selector"
    android:fastScrollEnabled="true" />
4

6 に答える 6

29

まず、タグは monodroid であるため、C# にあるため、受け入れられた回答は正しいです。

しかし、作者が望んでいるとは思いません...このトリックはキーボードを非表示にするだけですが、editTextにはまだフォーカスがあります。

Java と C# の両方でこれを行うには、これをルート Layout に配置する必要があります。

android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"

例えば ​​:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/white"
    android:descendantFocusability="beforeDescendants"
    android:focusableInTouchMode="true"
              >
....
</LinearLayout>
于 2013-04-03T08:00:22.500 に答える
13

これが解決策であることがわかりました:

Window.SetSoftInputMode (SoftInput.StateAlwaysHidden);

注: これは Java for Android ではなく C# です。

于 2012-05-15T19:22:56.580 に答える
8

これを onCreate に追加します

    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
于 2014-03-07T16:51:30.213 に答える
4

レイアウトでこれを試してください

<EditText
                    android:id="@+id/myid2"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@id/myid1"
                    android:clickable="true"
                    android:cursorVisible="false"
                    android:focusable="false"
                    android:hint="@string/hint"
                    android:singleLine="true"
                    android:textColor="@color/black"
                    android:textSize="15dp" />

そしてこれはあなたのコードで

    myEditText.setOnTouchListener(new OnTouchListener() {

        public boolean onTouch(View v, MotionEvent event) {

            if (event.getAction() == MotionEvent.ACTION_UP) {
                //do tasks
            }
            return false;
        }
    });

それが役に立つかどうかはわかりません。私はそれが何をするのかさえ知りません。しかし、それは私にとって同様の問題を解決しました。私があなたの時間を無駄にしたらごめんなさい

于 2012-05-15T03:24:58.790 に答える