26

Khi tôi cố gắng viết nội dung nào đó trong EditText nằm ở dưới cùng của màn hình, bàn phím mềm ẩn editText.how tôi có thể giải quyết vấn đề này không? bên dưới là mã xml của tôi. Tôi đang sử dụng màn hình này trong Phân đoạn.Bàn phím Android ẩn EditText

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" > 


     <LinearLayout 
      android:id="@+id/linearLayoutTopDetails" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/linearLayoutTop" 
      android:layout_marginLeft="6dp" 
      android:layout_marginRight="6dp" 
      android:layout_marginTop="6dp" 
      android:orientation="vertical" > 

      <LinearLayout 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:background="@drawable/list_design1" 
       android:orientation="vertical" > 

       <LinearLayout 
        android:layout_width="fill_parent" 
        android:layout_height="80dp" 
        android:layout_weight="100" 
        android:orientation="horizontal" > 

        <ImageView 
         android:id="@+id/ImageViewProfImagePostDetail" 
         android:layout_width="0dp" 
         android:layout_height="fill_parent" 
         android:layout_marginTop="2dp" 
         android:layout_weight="24.84" 
         android:paddingLeft="5dp" 
         android:paddingRight="5dp" 
         android:paddingTop="5dp" /> 

        <LinearLayout 
         android:layout_width="0dp" 
         android:layout_height="wrap_content" 
         android:layout_weight="60" 
         android:orientation="vertical" > 

         <TextView 
          android:id="@+id/textViewNamePostDetail" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:text="Robin" 
          android:textSize="17sp" /> 

         <TextView 
          android:id="@+id/textViewLocationPostDetail" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:layout_marginTop="1dp" 
          android:drawableLeft="@drawable/location" 
          android:text="beijing, China" /> 

         <TextView 
          android:id="@+id/textViewTimeAgoPostDetail" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:text=" 18min ago" /> 
        </LinearLayout> 

        <LinearLayout 
         android:layout_width="0dp" 
         android:layout_height="fill_parent" 
         android:layout_weight="15" 
         android:orientation="horizontal" > 

         <TextView 
          android:id="@+id/textViewReportAbusePostDetail" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:layout_gravity="center" 
          android:background="@drawable/flag" 
          android:paddingLeft="5dp" /> 

         <TextView 
          android:id="@+id/textViewDeletePostDetail" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:layout_gravity="center" 
          android:layout_marginLeft="15dp" 
          android:background="@drawable/delete" 
          android:visibility="gone" /> 
        </LinearLayout> 
       </LinearLayout> 

       <TextView 
        android:id="@+id/textViewDescriptionPostDetail" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginLeft="20dp" 
        android:layout_marginTop="2dp" 
        android:singleLine="false" 
        android:text="Description or caption of the post" 
        android:textSize="17sp" /> 
      </LinearLayout> 

      <ImageView 
       android:id="@+id/feedPostedImagePostDetail" 
       android:layout_width="fill_parent" 
       android:layout_height="200dp" 
       android:layout_marginTop="5dp" 
       android:scaleType="fitCenter" 
       android:visibility="gone" /> 

      <LinearLayout 
       android:id="@+id/linearLayoutOptions" 
       android:layout_width="fill_parent" 
       android:layout_height="33dp" 
       android:layout_marginTop="2dp" 
       android:layout_weight="100" 
       android:background="@drawable/bar" 
       android:orientation="horizontal" > 

       <TextView 
        android:id="@+id/textViewShakePostDetail" 
        android:layout_width="0dp" 
        android:layout_height="fill_parent" 
        android:layout_marginLeft="15dp" 
        android:layout_weight="25" 
        android:drawableLeft="@drawable/like" 
        android:gravity="center" 
        android:singleLine="true" 
        android:text="Shake" 
        android:textSize="12sp" /> 

       <TextView 
        android:id="@+id/textViewCommentPostDetail" 
        android:layout_width="0dp" 
        android:layout_height="fill_parent" 
        android:layout_weight="41" 
        android:drawableLeft="@drawable/comment" 
        android:gravity="center" 
        android:paddingLeft="20dp" 
        android:text="Comment" /> 

       <TextView 
        android:id="@+id/textViewSharePostDetail" 
        android:layout_width="0dp" 
        android:layout_height="fill_parent" 
        android:layout_weight="33" 
        android:drawableLeft="@drawable/share" 
        android:gravity="center" 
        android:paddingLeft="20dp" 
        android:text="Spread" /> 
      </LinearLayout> 
     </LinearLayout> 

     <ListView 
      android:id="@+id/listViewFeedsDetail1" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/linearLayoutTopDetails" 
      android:layout_marginBottom="4dp" 
      android:layout_marginLeft="6dp" 
      android:layout_marginRight="6dp" 
      android:layout_marginTop="6dp" > 
     </ListView> 

     <LinearLayout 
      android:id="@+id/linearLayoutPostcomment" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/listViewFeedsDetail1" 
      android:background="#FFFFFF" 
      android:orientation="horizontal" 
      android:weightSum="100" > 

      <EditText 
       android:id="@+id/editTextComment" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="80" /> 

      <Button 
       android:id="@+id/buttonPostComment" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="20" 
       android:background="#F0F8FF" 
       android:text="Post" > 
      </Button> 
     </LinearLayout> 
    </RelativeLayout> 
</ScrollView> 

'

Tôi đã cố gắng để giải quyết vấn đề này bằng cách thêm những thay đổi qua mã nhưng không thành công.

Dưới đây là hình ảnh trước và sau khi nhấp vào EditText. enter image description here

enter image description here

+1

scrollview không hoạt động. –

+1

Thêm thuộc tính này: android: windowSoftInputMode = "adjustPan | adjustResize" vào thẻ Hoạt động của bạn trong AndroidManifest.xml –

+0

bản sao có thể có của [Bàn phím mềm Android bao gồm trường edittext] (http://stackoverflow.com/questions/3295672/android-soft -keyboard-covers-edittext-field) – Lamorak

Trả lời

30

Trong đặt biểu hiện của bạn này trong hoạt động perticular của bạn:

android:windowSoftInputMode="adjustPan" 
+2

Tôi đã cố gắng này nhưng không thành công. android: windowSoftInputMode = "adjustPan | adjustResize" Mã này vẫn còn trong tệp kê khai của tôi.but vẫn đang ẩn editText. –

+0

cảm ơn @Kishan. làm việc quyến rũ cho tôi. –

14

Cho rằng bạn phải khai báo trong hoạt động của bạn manifeast

  <activity 
      android:name=".activityname" 
      android:label="@string/app_name" 
      android:windowSoftInputMode="adjustPan|adjustResize" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
+0

Đây là mã kê khai hoạt động của tôi. Điều này vẫn đang ẩn editText. –

+1

Đó là đoạn không phải là hoạt động. Tôi nên làm điều đó ở đâu? Tôi đã đặt mã này vào hoạt động trong đó phân đoạn được đặt. –

+4

@RobinRoyal có thể tôi đến trễ, nhưng (My có ích cho người khác) sử dụng một trong hai adjustPan hoặc adjustResize, không phải cả hai tại một thời điểm –

2

Sử dụng mã bên dưới nơi:

InputMethodManager ipmm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
       ipmm.hideSoftInputFromWindow(url.getWindowToken(), 0); 

nơi url trong mã của tôi là:

url = (EditText) findViewById(R.id.eT_webbrowser); 

hoặc Hãy thử điều này:

InputMethodManager ipmm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
        ipmm.hideSoftInputFromWindow(null, 0); 

Như một tùy chọn thử điều này: Đây luôn ẩn chế độ đầu vào mềm mà EditText của bạn có thể nhìn thấy

this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); 
+0

@Robin Royal - Nếu nó phù hợp với bạn, hãy chấp nhận nó như một câu trả lời. –

+0

Không di chuyển editText lên. –

+0

Tôi không nhận được bạn. Nhưng, bạn cũng đã thử với 'null' như một tùy chọn để kiểm tra? –

1

Khai báo cửa sổSoftInputMode = "adjustResize" trong tệp manifest.xml

<activity 
     android:name=".example" 
     android:theme="@style/AppTheme.NoActionBar" 
     android:windowSoftInputMode="adjustResize" /> 

cung cấp xem di chuyển đến tập tin layout xml

<RelativeLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:paddingBottom="16dp" 
     android:paddingLeft="16dp" 
     android:paddingRight="16dp" 
     android:paddingTop="16dp" 
     android:fitsSystemWindows="true"> 

<ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:fillViewport="true" 
     android:isScrollContainer="false"> 

    // add edittext here... 

</ScrollView> 
</RelativeLayout> 
2

Đây là giải pháp đơn giản cho Vấn đề về EditText của Android ẩn đằng sau SoftKeypad. Sử dụng mã trong tệp AndroidManifest.xml của mô-đun dự án.

<activity 
     android:name="com.example.MainActivity" 
     android:label="@string/activity_main" 
     android:windowSoftInputMode="adjustResize|stateHidden" /> 

Mã này làm việc cho tôi.
Bên trong file manifest trong thẻ hoạt động thêm thuộc tính này:

android:windowSoftInputMode="adjustResize|stateHidden" 

Có nhiều giá trị như vậy cho thuộc tính này (android:windowSoftInputMode) mà sẽ đến như danh sách khuyến nghị. Bạn cũng có thể kiểm tra với họ.

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