I have a below type structure,
<LinearLayout>
<ScrollView>
<LinearLayout>
<EditText1>
<EditText2>
<EditText3>
<EditText4>
<EditText5>
<EditText6>
<.......>
<.......>
<.......>
</LinearLayout>
</ScrollView>
My problem is when I select any of the EditText, the ScrollView should scroll in such a way that the selected EditText should be moved on to the top of the screen just after the action bar, and below the selected EditText the soft-keyboard should open.
Please give me some suggestions to accomplish this.
Regards,
open your manifest file of your project locate the activity in which you want the behavior you are looking for and write this as it's attribute
android:windowSoftInputMode="stateHidden|adjustPan"
Example
<activity
android:name=".SOMEActivity"
android:label="#string/some_title"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden|adjustPan" />
you can try different values for "windowSoftInputMode" attribute to see what exactly you want.
My application has structure like below-
<RelativeLayout>
...
<ScrollView>
<LinearLayout>
....
<EditText ... />
....
</LinearLayout>
</ScrollView>
...
</RelativeLayout>
When I am trying to input values in EditText, it loses focus and scrolls up to top.
It is focused when I first click it, but loses when I click any values (a-z) of softkeyboard.
Important issue is Application works fine on other devices and has this error only on certain devices (e.g. galaxy S4)
I already made 'adjustpan' and EditText's focusable true.
And there is no focus handling source in .java file.
Anyone has solution to this problem?
or Galaxy S4 has any issue on this problem?
I found the reason.
This issue only works on the condition below
Galaxy S4
using EditText with 'number' inputType
using gravity not left
(only horizontal gravity makes issue. any vertical gravity works as normal)
So I did like below
make empty space (marginBottom) so that keyboard may not block edittext
For some Edittext, set gravity to left and calculate device pixel and give edittext marginLeft
so that edittext works as if it's gravity is right
If anyone has better solution, please tell me how..
like in this post : Keyboard hides ListView contents
I can't See Contents of my first few rows of my ListView when Keyboard is Visible.
Because my first probleme was to have my element in the bottom so i've follow this tips : Android : Showing keyboard moves my components up, i want to hide them instead
but
android:windowSoftInputMode="adjustPan"
created another issue, my listview is not resize when my keyboard is up and i can't see my first few rows
Thanks
I had the same issue and solved this with the below code.
in your activity:
mylistview.setTranscriptMode(ListView.TRANSCRIPT_MODE_NORMAL);
mylistview.setStackFromBottom(true);
or in xml file for
android:stackFromBottom="true"
android:transcriptMode="normal"
and keeping the adjustResize for activity in manifest file.
<activity .... android:windowSoftInputMode="stateHidden|adjustResize" ..../>
Source: Push Listview when keyboard appears without adjustPan
I have an activity with a form in it. Because the form is quite long, I've used a scrollview.
The problem is that the scrollview doesn't change when the keyboard is up. The keyboard overlaps the last part of the scrollview.
How can I make sure that the keyboard is below the scrollview and the scrollview is adjusted to fit the space above it?
In the meanwhile, is there a way to make sure the buttons ‘previous’ and ‘next’ are in the keyboard as well?
In the application's manifest file, add the following to the desired <activity /> --
android:windowSoftInputMode="stateAlwaysHidden|adjustResize|adjustPan"
You need to add android:windowSoftInputMode="adjustResize" in the AndroidManifest.xml file.
if you use fragment, you just need to use the code to control it, like below
context.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
For ScrollView, I like to use the following soft input mode for the Activity in the AndroidManifest.xml file:
android:windowSoftInputMode="adjustPan"
This works the best for me out of the other options.
Note, if you are using CoordinatorLayout, make sure you set android:fitsSystemWindows="false" to be able to make it work for "adjustResize"
The above answers are not enough!
See this article
https://code.luasoftware.com/tutorials/android/move-layout-when-keyboard-shown/
<ScrollView ... android:layout_height="fill_parent" android:fillViewport="true" android:fitsSystemWindows="true" />
Manifest
<activity ... android:windowSoftInputMode="stateHidden|adjustResize" />
it's work for me
When the software keyboard shows, it resizes my layout and thus squeezes the background image together. My question is basically a duplicate of this question, which is explained in a very good way:
Software keyboard resizes background image on Android
However, that question was closed when they found a hack to solve it. I cannot use this hack. My entire layout is inside a ScrollView, and I need to be able to use this scrollview properly at all times. By using android:windowSoftInputMode="stateVisible|adjustPan" the user will not be able to scroll down and see the bottom of the screen while the keyboard is showing, since the layout will partly exist behind the keyboard. Thus the solution is unacceptable to me. Are there any better solutions out there?
Cheers,
I actually ran into a similar problem not too long ago. I stumbled upon the correct answer with a bit of work, though.
In your android manifest for this project, attached to the specific activity that you are using, use the line android:windowSoftInputMode="adjustPan|stateVisible" in the activity tag.
adjustPan basically means that your activity will not resize itself to fit the soft keyboard, and stateVisible means that the soft keyboard will show when requested (this can be stateAlwaysVisible, etc if necessary)
source :
Android Dev for Activity tags
After days of hardcore hacking I finally managed to construct a solution so advanced it might actually hurt to read it. I place an ImageView with the background behind the scrollview, and set scaleType="matrix" so it does not shrink when the keyboard is shown.
<?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="fill_parent"
android:background="#color/black"
>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="#drawable/mah_kewl_background"
android:scaleType="matrix"
/>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
>
<RelativeLayout
android:id="#+id/smsLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="PLUNX"
/>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
You can use the windowBackground property, which makes the drawable fit the whole screen.
To do that you need to:
1- Create a style:
<style name="Background" parent="#android:style/Theme.NoTitleBar">
<item name="android:windowBackground">#drawable/you_bg_drawable</item>
</style>
2- Set your activity style in the AndroidManifest.xml
<activity
android:name=".ui.your_activity"
android:theme="#style/Background"/>
I was googling for a solution to this exact problem when I came across this, and after doing some research I found a solution I think is slightly better. Instead of hacking with a ImageView you can use this from your activity:
getWindow().setBackgroundDrawableResource(R.drawable.bg_my_background);
Hope it helps anyone else searching for a solution for this.
I can't comment on your answer but I'd like to add something.
I understand your dilemma and why the solution you linked to isn't a complete solution for your situation (since you can't scroll to the bottom of the view). I have a similar situation with a large scrollable EditText box. When the soft keyboard pops up I don't like my background getting squished.
I have tried your solution and while at first glance it appears to work, there are some situations where it might not be ideal:
If you allow your app the have a landscape mode, the background will not resize/stretch
If you run your app on a device with a larger screen or dpi, your background may not fill the screen
Basically it seems that when you set the scaleType to matrix you're telling Android to draw the background 1:1 and not to scale. So what's happening when you open the soft keyboard using your solution is, your scrollView and imageView are all getting resized as usual, but the image src you set remains 1:1 thus continues showing the same area.
So if for example your background image was set to a specific size (e.g. 480 x 800) and it perfectly fills your Nexus One, the moment you rotate to landscape you will have a black area along the right.
This is moot, of course, if your background is simply a repeating pattern, in which case you can make it extremely large and hopefully compensate for various screens (maybe even tablets).
Or you can also supply different backgrounds for different screen sizes/densities/orientations, but this still doesn't account for scaling.
In a vain effort to try and solve this, I stumbled upon a View attribute called android:isScrollContainer. This attribute tells certain views whether or not they are allowed to resize upon display of the soft keyboard. This is also mentioned by someone in your linked solution. I have tried setting this (to false) on the ViewGroup containing my background, but any child element that scrolls seems override it causing the squishing again.
As of right now I don't think there is a complete solution for our situation. Your's definitely works in some instances and I thank you for the effort. Hopefully Google will offer a solution in the future, but I don't think they would consider this a problem/priority.
Maybe there's another (really simple!) solution:
In styles.xml:
create a new style like this:
<style name="Yourstyle" parent="AppBaseTheme">
<item name="android:windowBackground">#drawable/mybackground</item>
</style>
AppBaseTheme is your normally used theme for your app.
Then you add in Manifest.xml:
<activity
android:name="com.your.app.name.Activity"
android:theme="#style/Yourstyle">
</activity>
So you have the same style but with a background.
Important: don't set any backgrounds in your normal .xml file!
It's my first post and I hope it helps and sorry for my English.
in Androidmanifest in activity tag use:
<activity ... android:windowSoftInputMode="adjustPan" ></activity>
check Android Developer reference
How about a solution where the 'background' is a Layout. Can we inflate a layout, make it the entire window size, then insert it as a window background?
After a lot of time searching...
Put android:windowSoftInputMode="adjustPan|stateVisible" in each Activitys