I am using snack bar for displaying information, it is working fine if keyboard is not opened. If keyboard is opened the snack bar message displaying whole screen not displaying properly i am using android 5.5. I added this line android:windowSoftInputMode="adjustResize|stateAlwaysHidden" in my activity manifest but still same issue. Please help me for this issue. Please find the image below. My snack bar code is Snackbar.make(coordinator,getString(R.string.validation_plz_enter_mandatory_flds, UtilConstants.ERROR_CODE_UI_2000),Snackbar.LENGTH_INDEFINITE).show();
This is the Correct Solution of this problem: SnackBar show Above the SoftInput
(Keyboard) - (when Keyboard is Open)
<activity android:name=".YourActivity"
android:windowSoftInputMode="adjustResize"/>
tag into your activity tag of the manifest.
Have you initialized your snackbar like below code:
snackbar = Snackbar.make(findViewById(android.R.id.content), <Your message>, Snackbar.LENGTH_LONG);
or you have used your own layout??
Because if we use android's own UI element(android.R.id.content) it manages to show on valid UI of their own. You should first try this.
Put this property in your Manifest file to your proper activity.
<activity android:name=".YourActivity"
android:windowSoftInputMode="adjustResize"/>
Just Hide the KeyBoard where you call your SnackBar using below code:
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(parentLayout.getWindowToken(), 0); // parentLayout is your main layout of an activity
If your using CoordinatorLayout with AppBar and NestedLayout with EditText inside, it won't work.
This is a bug in support lib, reported here.
Similar question here.
You can use a workaround by wrapping the CoordinatorLayout with another Constraint/Relative Layout (PS I've not tried RealtiveLayout but works using ConstraintLayout) and use android:fitsSystemWindows="true".
with referenced to this answer.
Related
I am developing a Android Soft Keyboard. I want to create a layout above the Soft Keyboard. Whenever keyboard show on the screen the layout must visible.
You can easily understand my idea by seeing this image.
As mentioned by Jawad Ahmend in the comments, it's possible to attach the layout to the top of the keyboard by attaching it to the parent bottom using ConstraintLayout. You'd essentially need to do the following steps:
Set the windowSoftInputMode as adjustResize for your activity in the manifest.
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:windowSoftInputMode="adjustResize"
android:theme="#style/AppTheme.NoActionBar">
Set your layout visibility to gone and add a layout constraint attaching it's bottom to the bottom of the parent.
<LinearLayout android:id="#+id/layout_B"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone">
Next, you need to monitor the soft keyboard state. To keep this short, let's just use the KeyboardVisibilityEvent library. Add the following line to your app's build.gradle and sync it.
implementation 'net.yslibrary.keyboardvisibilityevent:keyboardvisibilityevent:2.3.0'
Add a keyboard listener in your activity to set your layout_B to become visible when the keyboard opens and you're done.
KeyboardVisibilityEvent.setEventListener(this) { keyboardIsOpen ->
layout_B.visibility = if (keyboardIsOpen) {
View.VISIBLE
} else {
View.GONE
}
}
If you're writing the keyboard, its easy. Just override onCreateInputView to return the view you want. This can easily be a linear layout with your extra views and the keyboard itself in it.
The bigger problem I see is you have an EditText in there. That's not going to work. Tapping on the EditText is going to break the InputConnection to the actual app and cause... unknown weird behavior. I'm not even sure if the behavior will be defined across different OS versions. It may cause the keyboard to immediately hide. It may cause the keyboard to just stop working at all. The OS isn't meant for that.
I'm using ActionBarSherlock. windowSoftInputMode is adjustPan (I've tried with adjustResize and adjustNothing also).
I want to keep ActionBar on screen when keyboard appears but slide my layout instead (so text remains visible).
Here is how it looks right:
And when keyboard is appeared:
Question is: how can I keep ActionBar visible while using adjustPan (so EditTexts will always be visible)?
NOTE
I can't use ScrollView to hold my View
I find out, that there may be problems with adjustResize (for some reason it's just uses adjustPan instead) when you applying FLAG_FULLSCREEN to Window of Activity:
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
Without this line resizing working just fine.
it looks like the layout slides up to make some space for the keyborad try:
add this to your manifest.xml:
<activity android:name=".YourActivity" android:label="#string/app_name" android:configChanges="keyboardHidden|orientation|keyboard" />
the important part is:
android:configChanges="keyboardHidden|orientation|keyboard"
android documentation manifest.xml
I want to act my tabs to have different windowSoftInputMode properties for each tab. How to access this property from java class when all handling of your tab is done from one single activity?
Is there any way to access this manifest property from java code?
Use the following to change the softInputMode for an Activity.
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
Use the following to change the softInput type for an EditText.
mEditText.setImeOptions(EditorInfo.IME_ACTION_DONE);
Thanks to #Eliezer for correction
According to Prasham's comment, I did this and it saved my life, thanks to him! The EditText and SoftWindowInput mode are quite buggy when you have a layout with ScrollView and you are filling it dynamically.
Since I had gone through this post but had continued to read other answers/comments (like Prashan's one), I decided to write it in a new post.
Below the code I used with my ScrollView:
Activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
I aim to use two different modes for tabs. The modes are SOFT_INPUT_ADJUST_RESIZE and SOFT_INPUT_ADJUST_NOTHING.
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
The code line above simply doesn't work by itself. App always behaves in a state ADJUST_NOTHING. However, if windowSoftInputMode="adjustResize" is inserted into <activity> tag in AndroidManifest.xml file, app window is resized as default. Additionally, when you call following line
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
it will behave as expected and nothing is resized.
P.S. improvement to the answer
In Xamarin Android You Can Do programatically Like This
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.DetailDesign);
Window.SetSoftInputMode(SoftInput.AdjustPan);
}
You can use the following code programmatically
android.view.inputmethod.InputMethodManager imm = (android.view.inputmethod.InputMethodManager) context
.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);
Thanks
Deepak
I have a vertical sliding drawer at the bottom of my app. When the soft keyboard opens, it pushes the tab for the drawer up, so it sits atop the keyboard. I actually want it to remain at the bottom of the screen, becoming hidden when the keyboard is shown.
Anyone else run into this issue? Know how to fix it?
You can simply switch your Activity's windowSoftInputModeflag to adjustPan in your AndroidMainfest.xml file inside your activity tag.
Check the official documentation for more info.
<activity
...
android:windowSoftInputMode="adjustPan">
</activity>
If your container is not changing size, then you likely have the height set to "match parent". If possible, set the parent to "Wrap Content", or a constraint layout with constraingts to top and bottom of parent.
The parent container will shrink to fit the available space, so it is likely that your content should be inside of a scolling view to prevent (depending on the phone manufacturer and the layout choosen...)
Content being smashed together
Content hanging off the screen
Content being inacccessable due to it being underneath the keyboard
even if the layout it is in is a relative or constraint layout, the content could exhibit problems 1-3.
None of the answers worked for me, but this did the trick, add this attribute to the activity tag in your AndroidManifest.xml:
<activity
...
android:windowSoftInputMode="adjustNothing">
</activity>
In my case, the reason the buttons got pushed up was because the view above them was a ScrollView, and it got collapsed with the buttons pushed up above the keyboard no matter what value of android:windowSoftInputMode I was setting.
I was able to avoid my bottom row of buttons getting pushed up by the soft keyboard by setting android:isScrollContainer="false" on the ScrollView that sits above the buttons.
You can try to add this attribute dynamically, by putting the following code in the onCreate method of your activity:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
This worked for me, but that:
android:windowSoftInputMode="adjustPan"
didnt.
These answers here didn't help me. So I tried this:
android:windowSoftInputMode="adjustResize"
This worked like a charm, Now the header of my app doesn't disappear. Its smoother.
To do this programatically in a fragment you can use following code
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
Place this in onResume()
This one worked for me
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
Just a single line to be added...
Add android:windowSoftInputMode="stateHidden|adjustPan" in required activity of your manifest file.
I just got solved :) :)
For future readers.
I wanted specific control over this issue, so this is what I did:
From a fragment or activity, hide your other views (that aren't needed while the keyboard is up), then restore them to solve this problem:
rootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
Rect r = new Rect();
rootView.getWindowVisibleDisplayFrame(r);
int heightDiff = rootView.getRootView().getHeight() - (r.bottom - r.top);
if (heightDiff > 100) { // if more than 100 pixels, its probably a keyboard...
//ok now we know the keyboard is up...
view_one.setVisibility(View.GONE);
view_two.setVisibility(View.GONE);
}else{
//ok now we know the keyboard is down...
view_one.setVisibility(View.VISIBLE);
view_two.setVisibility(View.VISIBLE);
}
}
});
So far the answers didn't help me as I have a button and a textInput field (side by side) below the textView which kept getting hidden by the keyboard, but this has solved my issue:
android:windowSoftInputMode="adjustResize"
For xamarin users add this code to Activity attribute of the MainActivity class,
WindowSoftInputMode =Android.Views.SoftInput.AdjustNothing
or you can add this code Window.SetSoftInputMode(Android.Views.SoftInput.AdjustNothing) to the OnCreate method of MainActivity class.
This was the best which worked for me
android:windowSoftInputMode="adjustNothing"
Try it!
Add following code to the 'activity' of Manifest file.
android:windowSoftInputMode="adjustResize"
android:windowSoftInputMode="stateHidden|adjustNothing"
This code works.
Well i have watched these answers but in my case i fell into the same issue and got refuge through a very handy and easiest solution that involves putting a very small innocent attribute in your Scrollview tag residing in your xml file. That is
android:isScrollContainer="false"
Good luck!
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
This one is working for me.
I have solved my issue by adding
android:windowSoftInputMode="adjustNothing"
In manifest file add.
and making the Recyclerviews constraint isScrollContainer to false .
android:isScrollContainer="false"
Try to use this:
android:windowSoftInputMode="stateHidden|adjustPan"
For Scroll View:
if after adding android:windowSoftInputMode="stateHidden|adjustPan" in your Android Manifest and still does not work.
It may be affected because when the keyboard appears, it will be into a scroll view and if your button/any objects is not in your scroll view then the objects will follow the keyboard and move its position.
Check out your xml where your button is and make sure it is under your scroll View bracket and not out of it.
Hope this helps out. :D
In my case I needed the keyboard to stay hidden and just after the click of the button my layout needs to be adjusted, so I just added this command in the manifest and it got super right.
android:windowSoftInputMode="stateHidden|adjustResize"
When you want to hide view when open keyboard.
Add this into your Activity in manifest file
android:windowSoftInputMode="stateHidden|adjustPan"
None of them worked for me, try this one
private void scrollingWhileKeyboard() {
drawerlayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
Rect r = new Rect();
try {
drawerlayout.getWindowVisibleDisplayFrame(r);
int screenHeight = drawerlayout.getRootView().getHeight();
int keypadHeight = screenHeight - r.bottom;
if (keypadHeight > screenHeight * 0.15) {
tabLayout.setVisibility(View.GONE);
} else {
tabLayout.setVisibility(View.VISIBLE);
}
} catch (NullPointerException e) {
}
}
});
}
I was struggling for a while with this problem. Some of the solutions worked however some of my views where still being pushed up while others weren't... So it didn't completely solve my problem. In the end, what did the job was adding the following line of code to my manifest in the activity tag...
android:windowSoftInputMode="stateHidden|adjustPan|adjustResize"
Good luck
The activity's main window will not resize to make room for the soft keyboard. Rather, the contents of the window will be automatically panned so that the current focus is never obscured by the keyboard and users can always see what they are typing.
android:windowSoftInputMode="adjustPan"
This might be a better solution for what you desired.
This code may help you. Use it in your oncreate method.
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
Include in your manifest file under activity which you want to display .But make sure not using Full screen Activity
android:windowSoftInputMode="adjustPan"
#manifest in your activity:
android:windowSoftInputMode="stateAlwaysHidden|adjustPan"
There are two ways of solving this problem.
Go to the AndroidManifist.xml, and in the name of your activity, add this line
android:windowSoftInputMode="adjustPan"
As in the below code, I have added to the Register Activity.
<activity android:name=".Register"
android:windowSoftInputMode="adjustPan">
In the second way, go to your activity, and in your onCreate method, add this code.
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
Is there a way to make the screen scroll to allow the text field to be seen?
I had same issues. Try following code:
android:windowSoftInputMode="adjustPan"
add it to your manifest.xml in the activity tag of the activity that holds the input. example:
<activity
android:name=".Activities.InputsActivity"
...
android:windowSoftInputMode="adjustPan"
/>
Are you asking how to control what is visible when the soft keyboard opens? You might want to play with the windowSoftInputMode. See developer docs for more discussion.
I had the same issue where the softkeyboard was on top of the EditText views which were placed on the bottom of the screen. I was able to find a solution by adding a single line to my AndroidManifest.xml file's relevant activity.
android:windowSoftInputMode="adjustResize|stateHidden"
This is how the whole activity tag looks like:
<activity
android:name="com.my.MainActivity"
android:screenOrientation="portrait"
android:label="#string/title_activity_main"
android:windowSoftInputMode="adjustResize|stateHidden" >
</activity>
Here the most important value is the adjustResize. This will shift the whole UI up to give room for the softkeyboard.
Why not try to add a ScrollView to wrap whatever it is you want to scroll. Here is how I have done it, where I actually leave a header on top which does not scroll, while the dialog widgets (in particular the EditTexts) scroll when you open soft keypad.
<LinearLayout android:id="#+id/HeaderLayout" >
<!-- Here add a header or whatever will not be scrolled. -->
</LinearLayout>
<ScrollView android:id="#+id/MainForm" >
<!-- Here add your edittexts or whatever will scroll. -->
</ScrollView>
I would typically have a LinearLayout inside the ScrollView, but that is up to you. Also, setting Scrollbar style to outsideInset helps, at least on my devices.
All you need to do is
android:isScrollContainer="true"
source: http://www.davidwparker.com/2011/08/25/android-fixing-window-resize-and-scrolling/
Sorry for reviving an old thread but no one mentioned setting android:imeOptions="flagNoFullscreen" in your EditText element
android:windowSoftInputMode="adjustPan"
android:isScrollContainer="true"
works for android EditText, while it not works for webview or xwalkview. When soft keyboard hide the input in webview or xwalkview you have use android:windowSoftInputMode="adjustResize"
I believe that you can make it scroll by using the trackball, which might be achieved programmatically through selection methods eventually, but it's just an idea. I know that the trackball method typically works, but as for the exact way to do this and make it work from code, I do not sure.
Hope that helps.
add this single line to your relative activity where key board cover edit text.inside onCreat()method of activity.
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
just add
android:gravity="bottom" android:paddingBottom="10dp"
change paddingBottom according to your size of edittext
I know this is old but none of the above solutions worked for me. After extensive debugging, I figured out the issue.
The solution is setting the android:windowTranslucentStatus attribute to false in my styles.xml
If EditText Field is been covered by the KeyBoard Use the following code:
EditText= findViewById(R.id.edittext)
EditText?.getParent()?.requestChildFocus(EditText,EditText)
If you want the Cursor to be in the Focused EditText than use EditText.requestFocus() after the EditText?.getParent()?.requestChildFocus(EditText,EditText) which helps to get the focus and Cursor in the Focused EditText.
The above solution work perfectly but if you are using Fullscreen activity(translucent status bar) then these solutions might not work.
so for fullscreen use this code inside your onCreate function on your Activity.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Window w = getWindow();
w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN , WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN );
getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, WindowManager.LayoutParams.TYPE_STATUS_BAR);
}
Example:
protected void onCreate(Bundle savedInstanceState) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Window w = getWindow();
w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN , WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN );
getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, WindowManager.LayoutParams.TYPE_STATUS_BAR);
}
super.onCreate(savedInstanceState);
Edit your AndroidManifest.xml
android:windowSoftInputMode="adjustResize"
Add this to your root view of Layout file.
android:fitsSystemWindows="true"
That's all.
I had the same issue and searching the people said to add adjustPan, while in my case adjustResize worked.
<activity
android:name=".YOUR.ACTIVITY"
...
android:windowSoftInputMode="adjustResize"
/>