2011-11-03 25 views
6

Tôi có EditText (người dùng có thể nhập số in), vì vậy khi người dùng nhấp vào hộp văn bản Chỉnh sửa bàn phím có số được mở.Android: Bàn phím trùng lặp với EditText (với màn hình in)

This is how it looks when the text box is clicked

như bạn sẽ nhìn thấy bàn phím ẩn một phần nhỏ trong hộp văn bản.

Nhưng khi tôi nhấn một phím, ví dụ: 0, có vẻ ổn. This is how it looks after after clicking 0

Có điều gì tôi có thể làm (ngoài việc đặt EditText cao hơn) để nó trông giống như trong hình thứ hai?

Edit: mã .xml:

<?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:weightSum="1"> 
    <RelativeLayout android:id="@+id/relativeLayout1" android:layout_width="fill_parent" android:layout_height="wrap_content"> 
    <LinearLayout android:layout_width="wrap_content" android:orientation="vertical" android:layout_height="wrap_content" android:id="@+id/linearLayout1" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_alignParentRight="true"> 
     <android.widget.CheckedTextView android:id="@+id/checkedTextView1" android:layout_height="wrap_content" android:layout_width="fill_parent" android:textSize="17sp" android:text="@string/toString"></android.widget.CheckedTextView> 
     <AutoCompleteTextView android:layout_height="wrap_content" android:id="@+id/autoCompleteTextView1" android:layout_width="fill_parent" android:text="@string/emptyString" android:textSize="17sp" android:gravity="top|left" android:minHeight="62dp"> 
      <requestFocus></requestFocus> 
     </AutoCompleteTextView> 
     <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/linearLayout2"> 
      <Button android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_weight="0.33333333333" android:text="@string/contactsString" android:textSize="17sp" android:id="@+id/contactsButton"></Button> 
      <Button android:layout_weight="0.33333333333" android:layout_height="wrap_content" android:text="@string/groupsString" android:layout_width="fill_parent" android:id="@+id/groupsButton" android:textSize="17sp"></Button> 
      <Button android:layout_weight="0.33333333333" android:layout_height="wrap_content" android:text="@string/favouritesString" android:layout_width="fill_parent" android:id="@+id/button3" android:textSize="17sp"></Button> 
     </LinearLayout> 
     <TextView android:id="@+id/textView1" android:text="@string/messageString" android:layout_height="wrap_content" android:textSize="17sp" android:layout_width="fill_parent"></TextView> 
     <EditText android:layout_height="wrap_content" android:id="@+id/editText1" android:layout_width="fill_parent" android:gravity="top|left" android:minHeight="105dp"></EditText> 
     <TextView android:id="@+id/textView2" android:text="@string/repetition" android:layout_height="wrap_content" android:layout_width="fill_parent" android:textSize="17sp"></TextView> 
     <Spinner android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/spinner"></Spinner> 
     <LinearLayout android:layout_height="wrap_content" android:id="@+id/linearLayout3" android:layout_width="fill_parent"> 
      <ImageView android:src="@drawable/button_time" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/imageView1" android:layout_weight="0.1"></ImageView> 
      <EditText android:layout_height="wrap_content" android:id="@+id/timeET" android:inputType="number" android:layout_width="wrap_content" android:layout_weight="0.4"></EditText> 
      <ImageView android:src="@drawable/button_date" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/imageView2" android:layout_weight="0.1"></ImageView> 
      <EditText android:layout_height="wrap_content" android:id="@+id/dateET" android:inputType="number" android:layout_width="wrap_content" android:layout_weight="0.4" android:layout_marginRight="3dp"></EditText> 
     </LinearLayout> 
     <RelativeLayout android:id="@+id/relativeLayout2" android:layout_width="fill_parent" android:layout_height="fill_parent"> 
      <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/linearLayout4" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:layout_alignParentLeft="true"> 
       <Button android:layout_weight="0.5" android:layout_height="wrap_content" android:text="@string/button_ok" android:layout_width="fill_parent" android:id="@+id/button4" android:textSize="17sp"></Button> 
       <Button android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="@+id/button5" android:layout_weight="0.5" android:text="@string/button_cancel" android:textSize="17sp"></Button> 
      </LinearLayout> 
     </RelativeLayout> 
    </LinearLayout> 
</RelativeLayout> 

</LinearLayout> 

Trả lời

18

Tôi đã thử XML của bạn và có bạn đúng là vấn đề xảy ra.

Để giải quyết vấn đề tôi đã viết dòng này trong MainActivity.java của tôi hy vọng sự trợ giúp này cho bạn, Và đặt XML bố cục trong ScrollView.

Hoạt động

public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.temp); 
     getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); 

     final EditText time = (EditText)findViewById(R.id.timeET); 
     time.setOnTouchListener(new OnTouchListener() { 

      public boolean onTouch(View v, MotionEvent event) { 
       time.requestLayout(); 
       MyActivity.this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED); 

       return false; 
      } 
     }); 
     final EditText date = (EditText)findViewById(R.id.dateET); 
     date.setOnTouchListener(new OnTouchListener() { 

      public boolean onTouch(View v, MotionEvent event) { 
       time.requestLayout(); 
       MyActivity.this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED); 

       return false; 
      } 
     }); 
     } 

And The XML là Giống như,

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

     <ScrollView android:id="@+id/scrollView1" 
     android:layout_height="fill_parent" 
     android:layout_width="fill_parent" 
     android:weightSum="1"> 
--- 
--- 
--- 
     </ScrollView> 
</LinearLayout> 
+0

Tôi sẽ cố gắng sau này vào ngày hôm nay hoặc sáng ngày mai và tôi sẽ cho bạn biết cách hoạt động của nó. cảm ơn! – Belgi

+0

p.s: ý của bạn là viết date.requestLayout(); tại date.setOnTouchListener? – Belgi

+0

@Frankenstein hehe cảm ơn bạn rất nhiều vì đã bình luận. Tôi muốn xóa câu trả lời của tôi ngay bây giờ nhưng bình luận của bạn đã ngăn cản tôi! Dù sao tôi trả lời khoảng tôi nghĩ rằng một ScrollView gốc sẽ giải quyết vấn đề. Có vẻ tôi đã nhầm. Tại sao chúng ta cần LinearLayout gốc trong câu trả lời của bạn? Tôi thực sự không có nhiều chi tiết về câu hỏi này nhưng tôi nghĩ rằng người nghe OnFocus là lựa chọn đúng đắn. Dù sao tôi không thể bình luận về chi tiết tôi có cuối tuần của tôi để thưởng thức. Cám ơn bạn một lần nữa !! +1 –

2

Bạn có thể đưa ra một số gợi ý để hệ thống về cách xử lý này qua android: yếu tố windowSoftInputMode về các hoạt động khai báo trong AndroidManifest. Hãy thử giá trị "adjustResize".

android:windowSoftInputMode

+0

này hoàn toàn ẩn EditText hộp văn bản – Belgi

2

Đặt android:windowSoftInputMode trên Hoạt động để "adjustPan":

cửa sổ chính của hoạt động không được thay đổi kích cỡ để nhường chỗ cho bàn phím mềm. Thay vào đó, nội dung của cửa sổ được tự động quét để tập trung hiện tại không bao giờ bị che khuất bởi bàn phím và người dùng luôn có thể xem nội dung họ đang nhập.

Hãy coi chừng one potential bug khi sử dụng kỹ thuật này với hoạt động toàn màn hình.

+0

Một lời giải thích trực quan hơn trong các phương thức đầu vào khác nhau, bao gồm một trong những gợi ý ở trên - mà nên làm như trick-, có thể được tìm thấy [ở đây ] (http://developer.android.com/resources/articles/on-screen-inputs.html). –

+0

Trông giống như trong pic đầu tiên:/ – Belgi

3

đặt toàn bộ chế độ xem bên trong ScrollView và đặt android:windowSoftInputMode = adjustPan nó sẽ thực hiện thủ thuật.

bạn chỉ cần thêm đoạn mã này,

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" > 

Your linear layout here.... 

</ScrollView> 

Tôi đã thử nghiệm nó trên HTC Desire của tôi và làm việc của nó tốt cho tôi hy vọng nó sẽ làm việc cho bạn quá.

+0

Bạn có thể giúp tôi cách tạo bố cục một ScrollView không? Tôi sẽ thêm mã .xml trong giây – Belgi

+0

Tôi đã đổi nó thành ScrollView nhưng nó đã làm rối loạn diện mạo hơn ... – Belgi

1

hãy thử thay đổi cách bố trí tuyến tính để cuộn xem ... để nếu bàn phím đi kèm trên người sử dụng văn bản editt có thể di chuyển và loại ...

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="fill_parent" 
android:layout_height="fill_parent" android:weightSum="1"> 
<RelativeLayout android:id="@+id/relativeLayout1" 
    android:layout_width="fill_parent" android:layout_height="wrap_content"> 
    <LinearLayout android:layout_width="wrap_content" 
     android:orientation="vertical" android:layout_height="wrap_content" 
     android:id="@+id/linearLayout1" android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" android:layout_alignParentTop="true" 
     android:layout_alignParentRight="true"> 
     <android.widget.CheckedTextView 
      android:id="@+id/checkedTextView1" android:layout_height="wrap_content" 
      android:layout_width="fill_parent" android:textSize="17sp"></android.widget.CheckedTextView> 
     <AutoCompleteTextView android:layout_height="wrap_content" 
      android:id="@+id/autoCompleteTextView1" android:layout_width="fill_parent" 
      android:textSize="17sp" android:gravity="top|left" 
      android:minHeight="62dp"> 
      <requestFocus></requestFocus> 
     </AutoCompleteTextView> 
     <LinearLayout android:layout_width="fill_parent" 
      android:layout_height="wrap_content" android:id="@+id/linearLayout2"> 
      <Button android:layout_height="wrap_content" 
       android:layout_width="fill_parent" android:layout_weight="0.33333333333" 
       android:textSize="17sp" android:id="@+id/contactsButton"></Button> 
      <Button android:layout_weight="0.33333333333" 
       android:layout_height="wrap_content" android:layout_width="fill_parent" 
       android:id="@+id/groupsButton" android:textSize="17sp"></Button> 
      <Button android:layout_weight="0.33333333333" 
       android:layout_height="wrap_content" android:layout_width="fill_parent" 
       android:id="@+id/button3" android:textSize="17sp"></Button> 
     </LinearLayout> 
     <TextView android:id="@+id/textView1" android:layout_height="wrap_content" 
      android:textSize="17sp" android:layout_width="fill_parent"></TextView> 
     <EditText android:layout_height="wrap_content" android:id="@+id/editText1" 
      android:layout_width="fill_parent" android:gravity="top|left" 
      android:minHeight="105dp"></EditText> 
     <TextView android:id="@+id/textView2" android:layout_height="wrap_content" 
      android:layout_width="fill_parent" android:textSize="17sp"></TextView> 
     <Spinner android:layout_width="fill_parent" 
      android:layout_height="wrap_content" android:id="@+id/spinner"></Spinner> 
     <LinearLayout android:layout_height="wrap_content" 
      android:id="@+id/linearLayout3" android:layout_width="fill_parent"> 
      <ImageView android:layout_width="wrap_content" 
       android:layout_height="wrap_content" android:id="@+id/imageView1" 
       android:layout_weight="0.1"></ImageView> 
      <EditText android:layout_height="wrap_content" android:id="@+id/timeET" 
       android:inputType="number" android:layout_width="wrap_content" 
       android:layout_weight="0.4"></EditText> 
      <ImageView android:layout_width="wrap_content" 
       android:layout_height="wrap_content" android:id="@+id/imageView2" 
       android:layout_weight="0.1"></ImageView> 
      <EditText android:layout_height="wrap_content" android:id="@+id/dateET" 
       android:inputType="number" android:layout_width="wrap_content" 
       android:layout_weight="0.4" android:layout_marginRight="3dp"></EditText> 
     </LinearLayout> 
     <RelativeLayout android:id="@+id/relativeLayout2" 
      android:layout_width="fill_parent" android:layout_height="fill_parent"> 
      <LinearLayout android:layout_width="wrap_content" 
       android:layout_height="wrap_content" android:id="@+id/linearLayout4" 
       android:layout_alignParentBottom="true" 
       android:layout_alignParentRight="true" 
       android:layout_alignParentLeft="true"> 
       <Button android:layout_weight="0.5" android:layout_height="wrap_content" 
        android:layout_width="fill_parent" android:id="@+id/button4" 
        android:textSize="17sp"></Button> 
       <Button android:layout_height="wrap_content" 
        android:layout_width="fill_parent" android:id="@+id/button5" 
        android:layout_weight="0.5" android:textSize="17sp"></Button> 
      </LinearLayout> 
     </RelativeLayout> 
    </LinearLayout> 
</RelativeLayout> 

xin vui lòng thực hiện thay đổi necesscery ... tôi đã gỡ bỏ dây và src drawable cho convience..u tôi cần phải thay đổi bố trí tuyến tính đầu tiên scrollview..try mà không android này: windowSoftInputMode = adjustPan

+0

Tôi đã đổi nó thành ScrollView nhưng nó làm rối loạn diện mạo hơn ... – Belgi

+0

tôi đã chỉnh sửa ... xin hãy xem ở trên – Rockin

5

thay đổi để scrollview theo cách này:

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 
    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:weightSum="1" > 
     <RelativeLayout 
      android:id="@+id/relativeLayout1" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" > 
      <LinearLayout 
       android:layout_width="wrap_content" 
       android:orientation="vertical" 
       android:layout_height="wrap_content" 
       android:id="@+id/linearLayout1" 
       android:layout_alignParentBottom="true" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentTop="true" 
       android:layout_alignParentRight="true" > 
       <android.widget.CheckedTextView 
        android:id="@+id/checkedTextView1" 
        android:layout_height="wrap_content" 
        android:layout_width="fill_parent" 
        android:textSize="17sp" 
        android:text="@string/toString" /> 
       <AutoCompleteTextView 
        android:layout_height="wrap_content" 
        android:id="@+id/autoCompleteTextView1" 
        android:layout_width="fill_parent" 
        android:text="@string/emptyString" 
        android:textSize="17sp" 
        android:gravity="top|left" 
        android:minHeight="62dp" > 
        <requestFocus></requestFocus> 
       </AutoCompleteTextView> 
       <LinearLayout 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:id="@+id/linearLayout2" > 
        <Button 
         android:layout_height="wrap_content" 
         android:layout_width="fill_parent" 
         android:layout_weight="0.33333333333" 
         android:text="@string/contactsString" 
         android:textSize="17sp" 
         android:id="@+id/contactsButton" /> 
        <Button 
         android:layout_weight="0.33333333333" 
         android:layout_height="wrap_content" 
         android:text="@string/groupsString" 
         android:layout_width="fill_parent" 
         android:id="@+id/groupsButton" 
         android:textSize="17sp" /> 
        <Button 
         android:layout_weight="0.33333333333" 
         android:layout_height="wrap_content" 
         android:text="@string/favouritesString" 
         android:layout_width="fill_parent" 
         android:id="@+id/button3" 
         android:textSize="17sp" /> 
       </LinearLayout> 
       <TextView 
        android:id="@+id/textView1" 
        android:text="@string/messageString" 
        android:layout_height="wrap_content" 
        android:textSize="17sp" 
        android:layout_width="fill_parent" /> 
       <EditText 
        android:layout_height="wrap_content" 
        android:id="@+id/editText1" 
        android:layout_width="fill_parent" 
        android:gravity="top|left" 
        android:minHeight="105dp" /> 
       <TextView 
        android:id="@+id/textView2" 
        android:text="@string/repetition" 
        android:layout_height="wrap_content" 
        android:layout_width="fill_parent" 
        android:textSize="17sp" /> 
       <Spinner 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:id="@+id/spinner" /> 
       <LinearLayout 
        android:layout_height="wrap_content" 
        android:id="@+id/linearLayout3" 
        android:layout_width="fill_parent" > 
        <ImageView 
         android:src="@drawable/button_time" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:id="@+id/imageView1" 
         android:layout_weight="0.1" /> 
        <EditText 
         android:layout_height="wrap_content" 
         android:id="@+id/timeET" 
         android:inputType="number" 
         android:layout_width="wrap_content" 
         android:layout_weight="0.4" /> 
        <ImageView 
         android:src="@drawable/button_date" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:id="@+id/imageView2" 
         android:layout_weight="0.1" /> 
        <EditText 
         android:layout_height="wrap_content" 
         android:id="@+id/dateET" 
         android:inputType="number" 
         android:layout_width="wrap_content" 
         android:layout_weight="0.4" 
         android:layout_marginRight="3dp" /> 
       </LinearLayout> 
       <RelativeLayout 
        android:id="@+id/relativeLayout2" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" > 
        <LinearLayout 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:id="@+id/linearLayout4" 
         android:layout_alignParentBottom="true" 
         android:layout_alignParentRight="true" 
         android:layout_alignParentLeft="true" > 
         <Button 
          android:layout_weight="0.5" 
          android:layout_height="wrap_content" 
          android:text="@string/button_ok" 
          android:layout_width="fill_parent" 
          android:id="@+id/button4" 
          android:textSize="17sp" /> 
         <Button 
          android:layout_height="wrap_content" 
          android:layout_width="fill_parent" 
          android:id="@+id/button5" 
          android:layout_weight="0.5" 
          android:text="@string/button_cancel" 
          android:textSize="17sp" /> 
        </LinearLayout> 
       </RelativeLayout> 
      </LinearLayout> 
     </RelativeLayout> 
    </LinearLayout> 
</ScrollView> 
+0

button_ok và nút4 (nút thats Cancel) không còn nằm trong phần mông của màn hình và keyboeard mở ra mà không có lý do ... – Belgi

+0

bạn có ' 'trên' autoCompleteTextView1'. Vì vậy, bàn phím phải mở! 'button_ok' và' button4' là điều cuối cùng trong bố trí của bạn .. Vì vậy, chúng phải ở dưới cùng của màn hình. –

+0

Mã được đăng không mở khóa phím. đúng là các nút này thấp hơn mọi thứ khác trên màn hình nhưng khoảng cách giữa thời gian và ngày EditText giờ đã biến mất nên các nút cao hơn. – Belgi

1

Đây là một sửa chữa đơn giản hơn nhiều so với câu trả lời chấp nhận. Điều quan trọng là dòng <item name="android:windowSoftInputMode">adjustUnspecified</item>. Thêm nó vào styles.xml của bạn:

<style name="AppTheme" parent="@android:Theme.Holo.Light.DarkActionBar"> 
    <item name="android:alertDialogTheme">@style/iconPopUpDialogTheme</item> 
</style> 

<style name="DialogAppTheme" parent="AppTheme"> 
    <item name="android:dialogTheme">@style/iconPopUpDialogTheme</item> 
</style> 

<style name="PopUpDialogTheme"> 
    <item name="android:windowSoftInputMode">adjustUnspecified</item> 
</style> 
Các vấn đề liên quan