In the pictures below you can see 2 EditText nicely standing next to each-other.
When I click on one EditText, it navigates me to the view (no problem). But when I click on the EditText next to it, the navigation send me a little upwards instead of staying on the same height. Anther problem is when I click in the previous EditText, bugging out the height and hiding the EditText from the view.
Normal
Click first (ok)
Click on the next one (problem)
Click back on the previous one (biggest problem), I end up a little below the view
Code:
<activity
android:name=".activity.ReportsEditActivity"
android:configChanges="orientation|screenSize"
android:label="#string/title_activity_reports_edit"
android:parentActivityName=".activity.MainActivity"
android:windowSoftInputMode="adjustResize|stateVisible">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".activity.MainActivity" />
</activity>
Edittext:
<EditText
android:id="#+id/report_template_grid_single_line_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="#dimen/grid_padding"
android:layout_marginStart="#dimen/grid_padding"
android:inputType="text"
android:maxHeight="#dimen/grid_element_max_height"
android:maxLines="1"
android:minHeight="#dimen/grid_element_min_height"
android:paddingBottom="#dimen/grid_element_top_and_bottom_padding"
android:gravity="top|start"
android:paddingEnd="#dimen/grid_element_top_and_bottom_padding"
android:paddingStart="#dimen/grid_element_top_and_bottom_padding"
android:paddingTop="#dimen/grid_element_top_and_bottom_padding"
android:textColor="#color/darkGray"
android:textSize="#dimen/grid_text_size_small" />
According to to developer document here.
https://developer.android.com/guide/topics/manifest/activity-element
Adjust resize keep activity's main window is always resized to make room for the soft keyboard on screen.
So you might need to use adjustPan something like this
<activity android:windowSoftInputMode="adjustPan"> </activity>
and when user hits back key you can handle the back key event in onBackpressed method to hide the soft keyboard.
Related
I don't want the soft keyboard to appear when a particular EditText is touched. But I still want to be able to show the soft keyboard upon user request (say, when a button is pressed) and allow the user to edit the text.
I know how to show/hide the soft keyboard, I only don't know how to prevent it from appearing on touch.
Any suggestion how to do it?
The general idea is that the user will be mostly working with selection/position within the text, and only occasionaly entering characters.
I don't want the visible amount of text to be reduced by the soft keyboard when selecting or navigating the text.
simply use
txtEdit.setShowSoftInputOnFocus(false);
and when you want to enable that , reverse above process
This works:
editText.setShowSoftInputOnFocus(false);
within the activity in the manifest add the below code
android:windowSoftInputMode="adjustPan"
AndroidManifest.xml windowSoftInputMode
<activity android:name=".MyActivity" android:windowSoftInputMode="adjustPan"> </activity>
Try the below code, it hides the keyboard:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN)
Why don't you disable the edittext. Then it will not show keyboard on click. To this you can:
android:editable="false" //from xml
et.setEnabled(false); //from activity
And then on your buttonClick make it enable by setting above code true. And make your keyboard appear.
Also If you don't get the focus on edittext you can:
et.requestFocus(); // from activity
<EditText
android:id="#+id/et1"
android:editable="false"
android:layout_width="150dp"
android:layout_height="wrap_content" >
<requestFocus/>
</EditText>
//from xml
Hope this helps!
I'm trying to make something like the image below, where the keyboard automatically opens when the activity starts and the EditText and the send button stick to the keyboard.
Use the below code to pop up the soft keyboard automatically when an activity launches
InputMethodManager imm = (InputMethodManager)getSystemService(
Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(youredittext, 0);
Make sure that you have not define android:windowSoftInputMode="stateHidden" in your manifest.xml.
To make an Edittext attach with the footer,use the following code:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#f3f3f3"
android:paddingBottom="10.0dip"
android:paddingTop="10.0dip"
android:id="#+id/bottom_bar" >
<EditText
android:id="#+id/et_send_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10.0dip"
android:layout_toLeftOf="#+id/ib_send"
android:hint="Enter Message"
android:singleLine="true" />
<ImageView
android:id="#+id/ib_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/et_send_bar"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/et_send_bar"
android:layout_marginBottom="1px"
android:layout_marginRight="10.0dip"
android:layout_marginTop="1px"
android:background="#drawable/chatsend_bg"
android:paddingBottom="5.0dip"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="5.0dip"
android:src="#drawable/ic_send_dark_normal" />
</RelativeLayout>
To show Keyboard at start of Activity you need to use like this:
<activity android:name="com.your.package.ActivityName"
android:windowSoftInputMode="stateVisible" />
From Android Docs:
stateVisible
The soft keyboard is visible when that's normally appropriate (when
the user is navigating forward to the activity's main window).
To hide Keyboard at start of Activity you need to use like this:
In your AndroidManifest.xml:
<activity android:name="com.your.package.ActivityName"
android:windowSoftInputMode="stateHidden" />
From Android Docs:
stateHidden
The soft keyboard is hidden when the user chooses the activity — that
is, when the user affirmatively navigates forward to the activity,
rather than backs into it because of leaving another activity.
This setting will hide soft keyboard when user enters new Activity (even if EditText control gains the focus). Soft keyboard will be shown only when user clicks the edit box control.
I have also found another solution for moving up layout components when Soft keyboard appers.
It can be achieved using adjustResize attribute in AndroidManifest.xml
Main purpose of adjustResize attribute is the activity's main window is always resized to make room for the soft keyboard on screen.
To show Keyboard and moved up EditText at start of Activity you need to use like this:
<activity android:name="com.your.package.ActivityName"
android:windowSoftInputMode="adjustResize" />
i think it will works for you:
Add this statement in manifest file to your Activity:
android:windowSoftInputMode="stateHidden"
<activity
android:name="ConversationActivity"
android:label="#string/title_activity_conversations"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden" />
I have a Spinner as:
<Spinner
android:id="#+id/test"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" />
It's inside a activity displayed as a dialog (I don't know if it matters, but...) <activity android:theme="#android:style/Theme.Holo.Light.Dialog" ... />
It works fine, showing all the five itens.
Until the keyboard I open the keyboard. Now, the first item is cut and cannot be scrolled to it.
I tried to put a listener for click in this spinner and close the keyboard, but I got an error java.lang.RuntimeException: Don't call setOnClickListener for an AdapterView. You probably want setOnItemClickListener instead
What is the fix for this behavior?
You probably need to change the soft input mode for the activity in your manifest file. Something like this:
<activity android:windowSoftInputMode="adjustResize" ... >
I have added a LinearLayOut having some buttons My screen is RelativeLayOut it self
Here is the code for that linear layout manager
<LinearLayout
android:orientation="horizontal"
android:gravity="bottom"
android:layout_alignParentBottom="true"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="#+id/Footer"
android:layout_marginBottom="5dp">
Here is the problem:
There is an EditText component on the top and it pops a soft keyboard on the screen , and brings my Footer manager on top of the keyboard and eventually SHATTERS my whole UI.
What is the exact solution?
P.S. I have removed android:gravity="bottom" and android:layout_alignParentBottom="true" one by one but with hard luck i did not get desired result.
Thanks
Add android:windowSoftInputMode="adjustPan" to manifest - to the corresponding activity:
<activity android:name="MyActivity"
...
android:windowSoftInputMode="adjustPan"
...
</activity>
You probably want
<activity
...
android:windowSoftInputMode="adjustNothing">
</activity>
That will prevent any layout changes when the soft keyboard is shown.
There is probably some confusion over this since it's currently missing from the documentation at http://developer.android.com/guide/topics/manifest/activity-element.html#wsoft
I have a screen where the first field is an EditText, and it gains the focus at startup, also popups the numeric input type, which is very annoying
How can I make sure that when the activity is started the focus is not gained, and/or the input panel is not raised?
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(editTextField.getWindowToken(), 0);
or
set activity property in manifest file as below in the application tag
android:windowSoftInputMode="stateHidden"
go to your application manifest file, and write this line for that activity you want to disable auto keyboard pop-up.
android:windowSoftInputMode="stateHidden"
To programatically not have the keyboard displayed, but the default widget still recieve focus call:
getWindow().setSoftInputMode(WindowManager.
LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
in onResume()
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
call the above method inside onCreate().It prevent softKeyboard to show unless user select EditText by tapping or clicking.
or simply add android:windowSoftInputMode="stateHidden" in Activity tag in Manifest.xml
This is usually a mess. The first thing I try is try to steal the focus with another view via . You also have to have the focusable and focusableInTouchMode.
<TextView
...
android:focusable="true"
android:focusableInTouchMode="true">
<requestFocus/>
</TextView>
Have another view grab focus. By default, the first focusable View will get focus when a layout is inflated. You can request focus on a different View via XML:
<TextView
android:layout_width="wrap_parent"
android:layout_height="wrap_content"
android:text="Some other view">
<requestFocus />
</TextView>
This works for any View.
If you want to do it programmatically, you can use view.requestFocus().
Adding android:windowSoftInputMode="stateHidden" to your Activity in manifest only hides the keyboard when you are launching the activity, or as Google says
When the user affirmatively navigates forward to the activity, rather
than backs into it because of leaving another activity
To hide the keyboard also when user presses the back button and moves back to your activity from some other activity, use android:windowSoftInputMode="stateAlwaysHidden"
if(getWindow().getAttributes().softInputMode==WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED)
{
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
}
have not tried this nor am i near my programming computer, but I would suspect programmatically sending focus to the parent view or something of that nature could do the trick - thats more likely a workaround than a solution, but again not able to test it just a thought