Keyboard overlaps Custom edit text - android

I have a an EditText with a drawable background (A rectangle shape with corners and a color, nothing fancy)
Case 1 When the EditText gets focus on click, view shifts above but the soft keyboard still partially overlaps it so that the hint is visible properly but the background is trimmed.
Case 2 (Inside a fragment, coz this issue does not occur in an Activity) If I press next from an edit text above the target EditText the background is again trimmed and the keyboard is just touching the bottom of the hint.
I have enclosed it inside a ScrollView, tried android:windowSoftInputMode="stateAlwaysHidden|adjustResize" (with different combinations too) but nothing seems to work.
Is there a way to override the y-axis by which the view is pushed when soft keyboard opens?

Half of the job is done by Scrollview itself,
Try to writing these line in you onFocusChanged method of edittext
editText.requestLayout();
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED);
and your .xml would be like -
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ScrollView
android:layout_height="match_parent"
android:layout_width="match_parent"
android:weightSum="1">
.... your editetexts here...
</ScrollView>
</LinearLayout>

Related

BottomSheetDialogFragment behaviour when showing keyboard [duplicate]

This question already has answers here:
Bottomsheet with edit text moved up by keyboard
(2 answers)
Closed 2 years ago.
I am using a BottomSheetDialogFragment which contains:
- A RecyclerView with a list of comments made by users
- A EditText at the bottom, where users can write a new comment and post it
When the user taps on the EditText, the keyboard shows up from the bottom.
What i want is the keyboard to push ONLY the EditText, so that the user can see what he's typing, but not push the whole BottomSheetDialogFragment.
You can see the desirable behaviour in the Facebook app for example.
I have tried setting different values for setSoftInputMode but all i can achieve is either to move the whole BottomSheetDialogFragment, or to move nothing (leaving the EditText covered).
The easiest way to do this is to not use a BottomSheetDialogFragment but instead to use a regular fragment that covers the entire window or an activity. Fragment or Activity; whichever you prefer doesn't matter as long as you're taking up the whole screen.
When the on-screen keyboard appears, the activity window (by default) resizes to make way for the on-screen keyboard.
Since a BottomSheetDialogFragment has it's gravity set to bottom, when the activity window resizes, it pushes the bottom sheet and all of it's contents upwards.
Here's an example of the simplest layout that can achieve what you're going for
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="80dp"
android:background="#80000000" />
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
First is a view with a constant height which imitates the dark area outside of a dialog. No matter how the window resizes this will always be 80dp.
Second is the RecyclerView which resizes based on the remaining available space the LinearLayout has. Pay attention to the attribute android:layout_weight.
Third is EditText which has a constant height of wrap_content. Again No matter how the window resizes this will always be the same height. Since the RecyclerView will take up as much space as it can, this EditText will remain at the bottom of the screen.
Once the window resizes due to the on-screen keyboard appearing, the LinearLayout will resize and recalculate it's children's sizes. Since the View and the EditText has a constant height it will have to make the RecyclerView smaller making it appear like the EditText moved upwards.
You don't have to use a LinearLayout to do this, you can achieve the same effect with any other layout. The key point here is to use a layout that takes up the whole screen.

Scrollable layout when keyboard pops up, but without focus change

I have a UX problem with my layout. I want that is possible that the user can scroll over the compleat layout without a focus change when the keyboard popes up.
This is what the Layout looks like when the activity starts
This is what happens when the user clicks to the Big Text EditText
This is what I want the layout to look like, the positions should stand in the same way as before, but it should be possible to scroll to the bottom with the keyboard open
The rootView of my layout is
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
I also try to add android:windowSoftInputMode="adjustResize" and android:windowSoftInputMode="adjustPan" the the activity in the Manifest.xml but it does not solve my problem.

How to stop a textview pushing layout off of screen

I am building a app and I just need some help with the attached screen shot.
Currently I have 5 Plain Textfields with the last 2 being textMultilines. I have a Relativelayout with a button placed at the bottom for the user to press submit. The problem is when the textViews above are filled in, especially the multiline ones, it will push the Relativelayout and button off the screen.
How can I stop this from happening
Picture of layout
Either You should fix the height of multi lines text or you can simply use Scroll View and put all the text view and button in same relative layout
You can make them Scrollable by adding ScrollView around them.
like
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
//all your views here
</LinearLayout>
</ScrollView>

Status bar always on screen

Good day (or evening, or night)
I'm developing an app for android and I'm very curious about one thing. I have an activity, where user chats with another, like "im" chat. There are an EditText on the bottom and some kind of actionbar on the top. What I need is when user enters a message and the software keyboard is on screen, my activity should move up, but the actionbar should still be "glued" to the top of the screen, because it has some valuable controls on it.
Again, that's not an ActionBar, but just a 48dp height layout in a parent vertical linear layout. So I need to know is there an easy way to prevent it from moving to the top, when the layout moves off the screen.
I tried to put everything in a FrameLayout and put this bar on top of it, but on keyboard opens it goes off the screen too...
On you Activity at AndroidManifest you should put this: android:windowSoftInputMode="adjustResize"
Use something like this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.myapp.MyActionBar
android:layout_width="match_parent"
android:layout_height="48dp"/>
<LinearLayout
android:id="#+id/mylayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1dp"/>
<!-- Add your edittext and button -->
</LinearLayout>
This will make sure the actionbar and edittext + button are allways on screen, and the mylayout takes up the rest of the screen. When your keyboard is shown, the mylayout will shrink.
Try adding android:windowSoftInputMode="adjustResize" to your activity in the manifest. This tells Android to completely resize your layout when the keyboard comes up, rather than pan it. Note that if there isn't enough room for the entire layout this still won't work. But you ought to be able to make it work if your top level layout is a RelativeLayout, with the edit text set to align bottom, the top bar to align top, and the middle section to fill_parent and be above the edit text and below the bar.
use a RelativeLayout as your base Layout and add android:layout_alignParentTop="true" to your action bar to keep it up
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="#+id/action_bar_layout"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_alignParentTop="true" >
</LinearLayout>
<TextView
android:id="#+id/text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>

Android force layout update after Visibility.GONE

I'm trying to hide the bottom bar when the keyboard is up. I use a size change listener on the list view to detect changes. When the keyboard is up I set the bottom bar to Visibility.GONE. What I get is the center image, which has the bottom bar GONE, but the window not resized correctly. What I want is the right image, which has the text input right above the keyboard. I think it has to do with the window still resizing while I set visibility to GONE?
I'm open to any other solutions besides modifying the visibility, as long as when the keyboard is up the text input is right next to it.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android">
<MyImageView
android:id="#+id/topbar"
style="#style/FillWidth"
android:src="#drawable/topbar"/>
<com.chess.genesis.MyListView
android:id="#+id/msg_list"
android:layout_below="#id/topbar"
android:layout_above="#+id/input_box"/>
<TableRow
android:id="#+id/input_box"
android:layout_above="#+id/botbar">
<EditText
android:id="#+id/new_msg"
style="#style/FillWidth"
android:layout_weight="82"
android:inputType="textCapSentences|textMultiLine"
android:maxLength="140"/>
<com.chess.genesis.MyImageView
android:id="#+id/submit_msg"
style="#style/FillWidth"
android:layout_weight="180"
android:layout_gravity="bottom"
android:layout_marginBottom="5dp"
android:src="#drawable/rsubmit"/>
</TableRow>
<MyImageView
android:id="#+id/botbar"
style="#style/FillWidth"
android:layout_alignParentBottom="true"
android:src="#drawable/botbar"/>
</RelativeLayout>
You can try to use layout_alignWithParentIfMissing for your input box.

Categories

Resources