2012-05-15 43 views
15

Tôi có một đơn giản EditText trên một ListView được xác định bên dưới.Android: EditText tự động bật bàn phím, cách dừng?

Khi ứng dụng chạy, EditText được chọn và bàn phím xuất hiện.

Tôi không muốn điều đó xảy ra. Tôi không muốn nó được chọn hoặc bàn phím xuất hiện theo mặc định.

<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" /> 
+0

http://stackoverflow.com/questions/2496901/android-on-screen-keyboard-auto-popping-up – FoamyGuy

+0

trùng lặp: http://stackoverflow.com/questions/106 11833/how-to-disable-keypad-popup-khi-on-edittext –

Trả lời

7

Tôi thấy điều này là giải pháp:

Window.SetSoftInputMode (SoftInput.StateAlwaysHidden); 

Lưu ý: Đây là trong C# không Java cho Android

+3

tại sao đây là câu trả lời được chấp nhận. Câu hỏi đặt ra là phát triển Android trong Java chứ không phải C#. – WallMobile

+0

Bạn có thể viết ứng dụng gốc của Android trong C#. Trong thực tế, bạn có thể viết iOS trong C# và chia sẻ 80% mã giữa hai biểu mẫu. 100% mã gốc. (Xamarin.com) –

+0

Về câu trả lời ở trên, bạn cũng có thể chỉ định điều này trong tệp kê khai cho Hoạt động như sau: 'android: windowSoftInputMode =" stateAlwaysHidden "'. –

2

thử điều này trong cách bố trí

<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" /> 

và điều này trong mã của bạn

myEditText.setOnTouchListener(new OnTouchListener() { 

     public boolean onTouch(View v, MotionEvent event) { 

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

tôi không biết nếu nó là của bất kỳ sử dụng. tôi thậm chí không biết nó làm gì. nhưng nó giải quyết được một vấn đề tương tự đối với tôi. sry nếu tôi lãng phí thời gian của bạn

25

Đầu tag là monodroid vì vậy nó trên C# nên câu trả lời được chấp nhận là chính xác.

Nhưng không phải những gì tôi nghĩ tác giả muốn ... mẹo này chỉ ẩn bàn phím nhưng editText vẫn có tiêu điểm.

Để làm điều này cả trong java và C#, bạn cần phải đặt này trong Layout gốc của bạn:

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

Ví dụ:

<?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> 
+0

thêm cả hai thuộc tính vào bố cục văn bản chỉnh sửa! Thêm nó vào rootlayout đã không giúp tôi! –

6

Thêm này trong onCreate

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

Bạn cũng có thể chỉ định điều này trong tệp kê khai cho Hoạt động như sau: 'android: windowSoftInputMode =" stateHidden "'. –

Các vấn đề liên quan