I have a linear layout and on the bottom of it I have an EditText.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:orientation="vertical"
android:gravity="center">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/text_view_id"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="#string/hello" />
<TextView
android:id="#+id/title"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="#string/hello" />
<TextView
android:id="#+id/description"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="#string/hello" />
</LinearLayout>
<EditText
android:id="#+id/plain_text_input"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:inputType="text"/>
</LinearLayout>
The problem is that when I run the app and click on the edittext the keyboard pops up and trims whatever I am typing so the text being type is not visible during typing as soon as I exit the edittext it becomes visible does anyone have a suggestion on how to make sure that the edittext view is visible while we enter the data and does not get trimmed by keyboard?
Try to add the below line in the manifest file in your particular Activity
android:windowSoftInputMode="adjustPan"
as explained here
Go to your AndroidManifest.xml file and in the specific activity use
`android:windowSoftInputMode="adjustResize"`
It should resolve your problem.
Related
In my Android application, I have ListView, with header contains 2 editText. When I try to focus on lower editText, the keyboard shows up, and changes focus to upper editText. Header layout xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/name"
android:hint="Title"
android:layout_alignParentTop="true"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nextFocusUp="#id/name"
android:inputType="text"
android:hint="Wordpack description"
android:id="#+id/description"
android:layout_below="#+id/name" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/description"
android:inputType="text"
android:id="#+id/locale"
android:text="Select language"/>
</RelativeLayout>
Seems like ListView is taking focus and giving it to the first child when you tap on it. Check out this answer. From the gist of it, you need to add the following in your activity on the manifest:
android:windowSoftInputMode="adjustPan"
And add this to your ListView:
android:descendantFocusability="beforeDescendants"
I'm creating an app that gets some values, you click in a button and it returns some other values and this views are distributed in 2 subLayouts of a bigger vertical LinearLayout like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp">
<RelativeLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_weight="0.4">
<EditText
android:layout_width="70dp"
android:layout_height="wrap_content"
android:inputType="number"
android:id="#+id/number1" />
<EditText
android:layout_width="70dp"
android:layout_height="wrap_content"
android:inputType="number"
android:id="#+id/number2"
android:layout_below="#+id/number1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Calc!"
android:id="#+id/calcButton"
android:layout_below="#+id/number2"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_weight="0.6"
android:layout_alignParentBottom="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Answer"
android:id="#+id/Answer" />
</RelativeLayout>
</LinearLayout>
My problem is that when I click on my EditText and the keyboard appears the answer's TextView goes up with the keyboard and "overrides" my button (the entire RelativeLayout follows the keyboard), there's a way of setting the RelativeLayout fixed so that it stays where it is mean to be?
Here what is happening:
There's a way of fixing that RelativeLayout?
Try setting android:windowSoftInputMode="adjustPan" for the activity in Android Manifest file.
I want to replicate this effect in my layout. But in my layout when the keyboard show up, my pop-up is not adjusted.
The device adjust me the main activity below and not the popup.
this is my popup layout.xml :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/sfondo_semi_trasparente_scuro">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="#color/white"
android:orientation="vertical">
<EditText
android:id="#+id/textNomeGiocatoreNewTeam"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:hint="Nome giocatore"/>
<EditText
android:id="#+id/textNumeroMagliaGiocatoreNewTeam"
android:inputType="number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Numero Maglia"/>
<Button
android:id="#+id/buttonConfirmAddNewPlayer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Aggiungi giocatore"
android:layout_gravity="center"/>
</LinearLayout>
Can someone help me?
Try instead this:popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
You can also add this to your AndroidManifest.xml
<activity
...
android:windowSoftInputMode="adjustResize"
</activity>
Somebody know how can avoid this black line above keyboard? It become after my keyboard shows prediction words line.
Line with help words
Line after help words
In my layer I use fragment and I need show line with EditText below. But when user ends typing, he sees black line above keyboard that is not need
Here is my code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<!-- TODO: Update blank fragment layout -->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:id="#+id/word_set_fragment_container"
>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Experimental layer"
/>
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#drawable/border"
android:paddingTop="5dp"
android:paddingBottom="3dp"
android:clickable="true"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="⇣"
android:layout_gravity="bottom"/>
<EditText
android:inputType="text|textCapSentences"
android:imeOptions="actionDone"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:hint="#string/hint_new_word"
android:text=""
/>
</LinearLayout>
</LinearLayout>
Sorry for my english.
In order to avoid black line in your keyboard, you should add layout_margin="0px" and android:padding="0px" to you keyboard layout xml file
<android.inputmethodservice.KeyboardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/keyboard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="0px"
android:padding="0px"
android:layout_alignParentBottom="true"
android:keyPreviewLayout ="#layout/preview"/>
This looks like its the actual android keyboard.. Which isn't something to change.
I'm designing a simple login activity. I've used the following xml layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center_vertical|center_horizontal"
android:layout_margin="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="My application title"
android:textSize="30sp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:orientation="vertical"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center_vertical"
android:layout_margin="15dp">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:layout_marginTop="15dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:text="Login"/>
</LinearLayout>
</LinearLayout>
And I've obtained this result:
But If the focus is on the first EditText I obtain this:
and If the focus is on the second EdiText the result is the follwoing:
Considering I've used the following line in the Manifest, for my activity:
android:windowSoftInputMode="adjustPan|adjustResize"
I want that when the virtual keyboard appears, the two edittext, the button and the textview are visible and correctly centered in the available screen.
What I have to change in my code?
NOTE: I've the same result If I remove the line in the manifest:
android:windowSoftInputMode="adjustPan|adjustResize"
You can replace the parent LinearLayout to a ScrollView :
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout ...>
....
....
</LinearLayout>
</ScrollView>
try this, it works for some of my apk !
Edit : sorry didn't see about center the text automaticaly, so with this you can adjust manually your editext to center with swipe your finger.. hope that will help