Spinner is cutting off dropdown list when showing keyboard - android

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" ... >

Related

Android: Entering text with soft keyboard in ScrollView pushing header views up

I spent hours debugging the same issue described in these SO questions:
Android: How do I prevent the soft keyboard from pushing my view up?
How to avoid soft keyboard pushing up my layout?
Android: How do I prevent the soft keyboard from pushing my view up?
The generally accepted answer is to add android:windowSoftInputMode="adjustPan" to the manifest activity declaration. This works to make the screen stay put when the keyboard is opened, however it does not stop the screen from scrolling when text is entered that has more lines than the screen can display. Here is what I see when I implement that solution:
The header remains when the keyboard opens, however if you type a bunch of lines the header eventually scrolls off the top of the screen.
I tried Googling this problem to try and solve it and none of the solutions worked. Then I managed to solve it by doing the opposite of what the accepted answer above said.
For reference, my layout xml file:
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintTop_toBottomOf="#id/header"
android:fillViewport="true">
<EditText
android:id="#+id/noteText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:windowSoftInputMode="adjustPan"/>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
My manifest:
<activity android:name=".activity.MainActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan"
android:resizeableActivity="true"
tools:targetApi="n"/>
I solved this by changing the manifest activity declaration to remove the android:windowSoftInputMode="adjustPan" line from the manifest:
<activity android:name=".activity.MainActivity"
android:screenOrientation="portrait"
android:resizeableActivity="true"
tools:targetApi="n"/>
...and now everything works as expected, the header stays on the screen when the keyboard was open and text was entered.
Hoping that I can save someone the time it took me to figure this out. Here is what it looks like after fixing the manifest:

Android EditText click navigation wrong

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.

SearchView show as always

i use widget SearchView
<SearchView
android:id="#+id/searchView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#color/white"
android:inputType="text"
android:singleLine="true"
android:layout_alignParentLeft="true"
/>
its work fine , but if search box show up, i always have to click on search icon then. so can anyone help me to make search box show up without click on search icon
Add the attribute
android:iconifiedByDefault="false"
to the SearchView definition.
You can add android:windowSoftInputMode="stateHidden" to the activity in the manifest file to prevent the keyboard from displaying; but before you do, think about this: If the user is forced to touch the widget to display the keyboard and enter something, you might as well leave the searchview iconified so that the user can see more of the display underneath.
If you really want to remove focus, there are a few alternatives, see this post: Stop EditText from gaining focus at Activity startup

Android : Showing keyboard moves my components up, i want to hide them instead

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

How to remove auto focus/keyboard popup of a field when the screen shows up?

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

Categories

Resources