Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add margin between EditText and Soft Keyboard?

I want to add 10dp margin between EditText and Soft Keyboard.

enter image description here Here is my XML:

<RelativeLayout     android:id="@+id/BottomLayout"     android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:layout_alignParentBottom="true"     android:layout_alignParentLeft="true"     android:background="@drawable/bottom_glass" >      <EditText         android:id="@+id/message"         android:layout_width="200dp"         android:layout_height="wrap_content"         android:layout_centerHorizontal="true"         android:layout_centerVertical="true"         android:background="@drawable/grey"         android:ems="10"         android:layout_marginBottom="10dp"         android:hint="Enter Message"         android:textColor="#ffffff" >       </EditText>      <ImageButton         android:id="@+id/sendMessageButton"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_centerVertical="true"         android:layout_marginLeft="20dp"         android:layout_toRightOf="@+id/message"         android:background="@android:color/transparent"         android:src="@drawable/sendselector" />      <ImageButton         android:id="@+id/imageButton2"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_centerVertical="true"         android:layout_marginRight="20dp"         android:layout_toLeftOf="@+id/message"         android:background="@android:color/transparent"         android:src="@drawable/sendmediaselector" />  </RelativeLayout> 

Here is my onCreate() :

    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);     messageText.setOnTouchListener(new OnTouchListener(){                  @Override                 public boolean onTouch(View v, MotionEvent event) {                             ((Swipe)getActivity()).getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED);                     return false;                 }}); 

I am using viewpager and full screen theme. The following EditText is in my 3rd fragment.

I've used android:windowSoftInputMode="adjustResize|adjustPan" and android:windowSoftInputMode="adjustResize", but nothing happened.

like image 817
Punit Avatar asked Jan 29 '14 20:01

Punit


People also ask

How do I get the keyboard to show in EditText?

edittext. requestFocus(); -> in code. This will open soft keyboard on which edit-text has request focus as activity appears. This open the keyboard at Activity creation.

How do you create EditText in XML?

First of all, create a new Android app, or take an existing app to edit it. In both the case, there must be an XML layout activity file and a Java class file linked to this activity. Open the Activity file and include a Edittext field in the layout (activity_main.

Which of the following method is used to set the EditText text?

In android, we can set the text of EditText control either while declaring it in Layout file or by using setText() method in Activity file.


2 Answers

I find the attribute of paddingBottom can effect the distance between the editText and the keyboard. You can do like this:

<RelativeLayout      android:layout_width="match_parent"      android:layout_height="110dp">    <ImageView      android:layout_width="match_parent"      android:layout_height="100dp"      android:background="@drawable/your_edit_text_background"/>      <EditText      android:layout_width="match_parent"      android:layout_height="match_parent"      android:paddingBottom="10dp"/>  </RelativeLayout> 

This will make your keyboard margin your EditText by 10dp

like image 178
summer1991 Avatar answered Oct 07 '22 19:10

summer1991


This seems to work, though has some unwanted effect on the layout.

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); 

If anybody knows how to get this working with ADJUST_PAN, that would be great!

like image 20
Veeru Avatar answered Oct 07 '22 17:10

Veeru