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"
Related
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.
edit:
I need to use the keyboard, but it hides my EditText, I need it to scroll so the keyboard is not hiding it.
I am using a Samsung tablet.
My style:
parent="android:Theme.Holo.NoActionBar.Fullscreen"
The EditText fields are in a scrollable view, like so:
The fragment layout:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin">
<ScrollView
android:layout_height="wrap_content"
android:layout_width="match_parent">
<LinearLayout
android:layout_height="match_parent"
android:layout_marginBottom="20dp"
android:layout_width="match_parent"
android:orientation="vertical">
<TextView
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:text="#string/depot_code"/>
<EditText
android:hint="#string/enter_depot_code"
android:id="#+id/etlocationId"
android:imeOptions="actionNext"
android:inputType="number"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:lines="1"
android:maxLength="12"
android:singleLine="true">
<requestFocus/>
</EditText>
<TextView
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:text="#string/name"/>
<EditText
android:hint="#string/enter_name"
android:id="#+id/etname"
android:imeOptions="actionNext"
android:inputType="textPersonName"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:lines="1"
android:maxLength="24"
android:singleLine="true"/>
<TextView
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:text="#string/street"/>
<EditText
android:hint="#string/enter_street"
android:id="#+id/etstreet"
android:imeOptions="actionNext"
android:inputType="textPostalAddress"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:lines="1"
android:maxLength="24"
android:singleLine="true"/>
<TextView
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:text="#string/suburb"/>
<EditText
android:hint="#string/enter_suburb"
android:id="#+id/etsuburb"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:lines="1"
android:maxLength="24"
android:singleLine="true"/>
<TextView
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:text="#string/state"/>
<Spinner
android:focusable="true"
android:focusableInTouchMode="true"
android:id="#+id/spinner"
android:imeOptions="actionNext"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_width="fill_parent"
android:spinnerMode="dropdown"/>
<TextView
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:text="#string/phone"/>
<EditText
android:hint="#string/enter_phone"
android:id="#+id/etphone"
android:imeOptions="actionDone"
android:inputType="phone"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:lines="1"
android:maxLength="12"
android:singleLine="true"/>
<Button
android:id="#+id/btnadd"
android:layout_gravity="center"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:text="#string/add"/>
</LinearLayout>
</ScrollView>
</FrameLayout>
The Activity layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tech_controller"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin">
< .../ Layouts. ../>
<FrameLayout
android:id="#+id/second"
android:layout_height="match_parent"
android:layout_width="fill_parent"/>
</LinearLayout>
Similar questions have been asked, but I have not found an answer that works.
I have a project that uses many fragments attached to the one activity.
In my manifest for the activity I have:
android:windowSoftInputMode="stateHidden"
Some of the fragments require user input.
In the fragment layout I use:
Each fragment is nested as follows:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent" .../>
<ScrollView
android:layout_height="match_parent"
android:layout_width="match_parent">
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
<EditText
android:imeOptions="actionNext"
or
android:imeOptions="actionDone" .../>
This works well. EXCEPT
the keyboard hides the EditTexts that are positioned lower on the page.
I have read this over and over:
http://developer.android.com/reference/android/widget/TextView.html#attr_android:imeOptions
Tried these suggestions, but the keyboard is then visible when the activity is called, which I don't want. It also does not work. Maybe because it is a fragment?
SoftKeyboard hiding EditText
Android Keyboard hides EditText
I have been trying to work out a dynamic solution. Any help is appreciated.
edit: This is for use on tablets and there is only one keyboard option, with language changes.
Edit: MY SOLUTION
I have solved it by installing another soft keyboard. https://code.google.com/p/softkeyboard/wiki/HowTo
Try to use WindowsSoftInputMode as adjustpan only.
For ex:
android:windowSoftInputMode="adjustPan"
Try to call InputMethodManager.hideSoftInputFromWindow() during your fragment's onActivityCreated() function mentioned in this SO answer?
#Override
public void onActivityCreated(#Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
AppUtil.hideKeyboard(getActivity(), getView());
}
where hideKeyboard() looks like this
public static void hideKeyboard(Activity activity, View viewToHide) {
InputMethodManager imm = (InputMethodManager) activity
.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(viewToHide.getWindowToken(), 0);
}
You can try to put this in onActivityCreated of your fragment:
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
This should not make the keyboard upon loading or starting of your activity with fragment.
I have tried this code and resolve my issue.
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
I solved the problem by installing another soft keyboard, via the google play store.
It was Petey's comments that made me explore this solution.
The IME you used has it's own "floating" layout, can you try your code with built-in IMEs like Google Keyboard or set your IME to a normal full-width layout?
So I figured, no amount of playing with the view layout was going to affect a soft keyboard that has an independent layout.
I used this link https://code.google.com/p/softkeyboard/wiki/HowTo
It even works with Android Manifest:
android:windowSoftInputMode="stateHidden"
I then use imeoptions to control the flow of the editor cursor within the view.
edit update
I just tried the app on a no-brand android tablet, which comes with comes with a generic android keyboard and it works, without having to change a thing. It seems the Samsung default keyboard is painful.
Change this to LinearLayout:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
to
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin">
(and the closing tag). Note the orientation.
Update the manifest Remove this:
<application ... >
<activity
android:windowSoftInputMode="stateVisible|adjustResize|adjustPan">
...
</activity>
...
</application>
Change this (height):
<ScrollView
android:layout_height="wrap_content"
android:layout_width="match_parent">
keep in mind that hide keyboard does not work with
getActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
Before show your Snackbar widget hide the keyboard like this,
public void showSnackBar(){
InputMethodManager manager = (InputMethodManager)getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE);
manager.hideSoftInputFromWindow(getView().getWindowToken(),0);
Snackbar snackbar = Snackbar.make(getView(), "Some message!", Snackbar.LENGTH_INDEFINITE).show();
}
What worked for me was using the ScrollView the same way as you in my FrameLayout, in which I added this property: android:windowSoftInputMode="adjustPan". At the end, it looks like this and it is working. I did not need to change anything programatically:
<FrameLayout 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"
tools:context=".ProductFragment"
android:windowSoftInputMode="adjustPan">
<ScrollView
android:layout_height="wrap_content"
android:layout_width="match_parent">
...
</ScrollView>
</FrameLayout>
I have an activty that contains listview and on the bottom there is edittext andbottom aligned
similar to whatsapp default activty
when I click on the edittext on the bottom the soft keyboard pushes the bottom and the edit text up but it doest do the same for the list view so the bottom part of the list view disapear under the botton and the text view
here is my XML
<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="wrap_content"
android:orientation="vertical"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="com.test.testsms.app.SMSList">
<ListView
android:id="#+id/contactList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:dividerHeight="0px"
android:divider="#00000000"
>
</ListView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:text="#string/app_name"
android:id="#+id/Button"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</Button>
<EditText
android:id="#+id/EditText"
android:layout_width="fill_parent"
android:layout_toLeftOf="#id/Button"
android:layout_height="wrap_content">
</EditText>
</LinearLayout>
</LinearLayout>
If you want to push edittext up with keyboard, you have to set RelativeLayout instead of main RinearLayout. so LinearLayout included with edittext and button will be located in bottom of activity. and when you click the edittext, the keyboard will be push up with it.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
...<ListView>
<EditText
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:selectAllOnFocus="true"
android:textStyle="normal"
>
</EditText>
</RelativeLayout>
Edit your AndroidManifest.xml and add/modify your activity's android:windowSoftInputMode attribute. See http://developer.android.com/guide/topics/manifest/activity-element.html#wsoft for a list of what each option can do. Sounds like you might want to try adjustPan
How can I format a header, a list, and an EditText so that the EditText is a fixed single line and always visible?
Here is my layout with only one list entry - EditText fills the rest of the screen which looks bad.
Here is the layout with several list entries - the soft keyboard hides the text being typed. I was typing in Wayne.
I have tried a various Linear and Relative layouts. Here is my current Layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/select_child_header"
style="#style/headerStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#color/start_blue"
android:text="Which child did you take a picture of?" />
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/modchild_fragment"
android:name="com.chex.control.ChildList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/select_child_header"
android:focusable="true"
android:focusableInTouchMode="true" >
</fragment>
<EditText
android:id="#+id/new_child"
style="#style/editTextStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_below="#id/modchild_fragment"
android:hint="new child name"
android:inputType="text"
android:singleLine="true" />
</RelativeLayout>
I appreciate any advice on how to format this screen.
For this you have a two options one is In textview there is a tag called android:singleLine="true" if you do like this the text comes in a single line and it miss the some text and show some dots..
And another way is you have to decrease the fontsize.. by using this tag..android:textSize="3sp"
Try this way
<?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" >
<TextView
android:id="#+id/select_child_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="Which child did you take a picture of?" />
<fragment
android:id="#+id/modchild_fragment"
android:name="com.chex.control.ChildList"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:focusable="true"
android:focusableInTouchMode="true" >
</fragment>
<EditText
android:id="#+id/new_child"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_below="#id/modchild_fragment"
android:hint="new child name"
android:inputType="text"
android:singleLine="true" />
</LinearLayout>
Set
android:ellipsize=end
android:singleLine="true"
Change the order and positioning of your elements:
add first the header on top
add the bottom edittext
add the fragment in-between
Something like:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/select_child_header"
style="#style/headerStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#color/start_blue"
android:text="Which child did you take a picture of?" />
<EditText
android:id="#+id/new_child"
style="#style/editTextStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:hint="new child name"
android:inputType="text"
android:singleLine="true" />
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/modchild_fragment"
android:name="com.chex.control.ChildList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/new_child"
android:layout_below="#id/select_child_header"
android:focusable="true"
android:focusableInTouchMode="true" >
</fragment>
</RelativeLayout>
Add
android:maxLines="1"
to your EditText, to get desired number of lines .
You can set the static height to the Fragment. So that if your list item say for example, one or more than 5 also, your edit text constitutes the bottom layer of fragment.
Also, you can set android:singleLine="true" property to edittext.
I have a fragment with a listview and an edittext.
When the edittext gains focus all the layout except the edittext turns black for one second.
If I hold the edittext clicked then the surrounding layout stays black until I scroll the list, or touch the screen, it only happens on Jelly Bean 4.1.2.
Here is my 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"
android:background="#null"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/search_layout"
android:layout_width="fill_parent"
android:layout_height="49.33dp"
android:background="#color/grey">
<EditText
android:id="#+id/search_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:layout_marginRight="5dp"
android:background="#drawable/searchbox"
android:drawableLeft="#drawable/search_icon"
android:ems="8"
android:hint="#string/search_hint"
android:maxLines="1"
android:padding="3dp"
android:paddingLeft="15dp"
android:paddingRight="25dp"
android:singleLine="true" />
</RelativeLayout>
<com.emilsjolander.components.stickylistheaders.StickyListHeadersListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/search_layout"
android:divider="#color/light_blue"
android:dividerHeight="0.67dp" />
</RelativeLayout>
What can be the causes for that behavior ?
Add the following line to your listview(in xml) and try..
android:cacheColorHint="#00000000"
Hope it works!!