all I am working on performing scrolling while the keyboard is open! My Screen is not scrolling upside while the keyboard appears. I want my screen need to scroll upside when the keyboard appears. As well as it showing me the bottom of the layout. Please suggest guidelines to fulfill that requirement. Is there any other way to do that thing?..... Thanks in advance.
I have tried many of them -
In the manifest file put that snippet :
android:windowSoftInputMode="adjustPan"
android:windowSoftInputMode="adjustResize|stateHidden"
In XML file added the properties:
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/appBarLayout"
android:fillViewport="true"
android:fitsSystemWindows="true"
android:scrollbars="none">
But, this too didn't work. Please suggest any proper solution to it.
This is my XML file :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".work.CreateClassActivity">
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#color/ColorsWhite"
android:theme="#style/AppTheme.AppBarOverlay">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:weightSum="1"
app:popupTheme="#style/AppTheme.PopupOverlay">
<RelativeLayout
android:id="#+id/relativeLayoutLogo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.00"
android:visibility="visible">
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:text="#string/create_class"
android:textColor="#color/colorTextDarkBlue"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/appBarLayout"
android:fillViewport="true"
android:fitsSystemWindows="true"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:focusable="true"
android:focusableInTouchMode="true"
android:weightSum="5">
</LinearLayout>
</ScrollView>
</RelativeLayout>
And this is my manifest file snippet:
<activity
android:name=".work.CreateClassActivity"
android:launchMode="singleTask"
android:screenOrientation="landscape"
android:windowSoftInputMode="adjustResize|stateHidden"
android:theme="#style/AppTheme.NoActionBar" />
You just need to use adjustPan not adjustResize on the corresponding activity in AndroidManifest.xml. You just need to adjust it like this.
<activity
android:name=".work.CreateClassActivity"
android:launchMode="singleTask"
android:screenOrientation="landscape"
android:windowSoftInputMode="adjustPan"
android:theme="#style/AppTheme.NoActionBar" />
Solution -
Step - 1 : In manifest file put that line in your particular activity:
android:windowSoftInputMode="adjustResize"
Step - 2 : In java file and in onCreate() put that line :
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
Step - 3 : Before run the project - first clean project and uninstall previous apk.
Step - 4 : Run the project and you will get that desired result.
Related
I need to show my button to top of soft keyboard (when it's opened). For this I implement this https://medium.com/#madalinnita/android-how-to-move-views-above-keyboard-when-its-opened-quick-secure-solution-90188c4d7b15.
My layout structure:
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical">
<androidx.core.widget.NestedScrollView
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:isScrollContainer="true"
app:layout_constraintBottom_toTopOf="#+id/bottomContainer"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText..../>
<EditText..../>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
<Button
android:id="#+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:gravity="end"/>
</androidx.constraintlayout.widget.ConstraintLayout>
And everything working fine, but in small devices my button covers edit text. Is it possible to fix it? I don't have any ideas. I need to somehow make the button and keyboard appear under edit text even on small devices.
Please, help me.
You can wrap your whole view inside a ScrollView which would then allow you to scroll the view while the keyboard is open.
In this example I am using a LinearLayout you can use other layouts as well.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
...
</LinearLayout>
</ScrollView>
And add to your Manifest for the specific activity this line of code:
android:windowSoftInputMode="adjustResize"
Add this line -> android:windowSoftInputMode="adjustResize", in your current activity tag in Manifest as follow
<?xml version="1.0" encoding="utf-8"?>
<manifest ...>
<uses-permission android:name="android.permission.INTERNET" />
<application
...
...>
<activity
android:name=".MainActivity"
android:windowSoftInputMode="adjustResize"
...
/>
...
</application>
</manifest>
I've got a simple fragment layout:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/BrightYellowCrayola"
>
<androidx.appcompat.widget.Toolbar
android:id="#+id/tbDriver"
app:navigationIcon="#drawable/baseline_menu_24"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways"
>
<androidx.appcompat.widget.SearchView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:defaultQueryHint="#string/search_drivers"
app:iconifiedByDefault="false"
app:searchIcon="#null"
app:queryBackground="#android:color/transparent"
app:submitBackground="#android:color/transparent"
/>
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/swipe_refresh_layout_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycler_view_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingStart="#dimen/zero_margin_when_normal"
android:paddingEnd="#dimen/zero_margin_when_normal" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/efab_recycler_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
app:backgroundTint="#color/BrightYellowCrayola"
android:src="#drawable/baseline_person_add_24" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
The issue is that after I enter a text in my serchfield and I rotate the phone, the searchview keeps focus (keyboard) for a short period of time and then dissapears again as seen in this example
NOTE!:
However, the "funny" thing is that this only happens if I rotate the phone horizontally, when I orientate my phone verticaly, the soft-keyboard appears again.
Try adding the following line in your searchview:
android:imeOptions="flagNoExtractUi"
So the endresult should look like this:
<androidx.appcompat.widget.SearchView
android:id="#+id/svDriver"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:defaultQueryHint="#string/search_drivers"
app:iconifiedByDefault="false"
app:searchIcon="#null"
app:queryBackground="#android:color/transparent"
app:submitBackground="#android:color/transparent"
android:imeOptions="flagNoExtractUi"
/>
Add the below line in your manifest.xml file
<activity
android:name=".MyActivity"
android:windowSoftInputMode="stateUnchanged|adjustPan" >
"stateUnchanged" will make the state of keyboard same as it was in earlier state. Either hidden or visible.
"adjustResize" will make your edit text visible.
I'm developing an Android Layout with Xamarin.
When the keyboard is visible, the layout is compressed.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:weightSum="20"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="3dp"
android:background="#drawable/faded_div"/>
<LinearLayout
android:id="#+id/div1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:gravity="center_vertical"/>
<ScrollView
android:id="#+id/scroll"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="16"
android:orientation="vertical"/>
<RelativeLayout
android:id="#+id/div2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2">
<Common.Droid.UI.Controls.NXButton
android:layout_height="44dp"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:text="Aplicar"/>
</RelativeLayout>
</LinearLayout>
The goal is for the keyboard to overlay the layout.
How can I prevent the screen from moving when the keyboard is visible?
Can you help me?
Test it
<activity android:name=".UserRegistration"
android:windowSoftInputMode="adjustNothing">
Tell me the result after the test
in xamarin native andorid use this syntax code on your Activity for prevent the screen moving:
Window.SetSoftInputMode(SoftInput.AdjustNothing);
i do not want to move my layout which has several views in it so when user touch edit text then keyboard open and my layout widget goes up. I have even use code in manifest
android:windowSoftInputMode="adjustPan"
then
android:windowSoftInputMode="adjustPan|adjustResize"
Nothing work so please help me
Here is my xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeAdd"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="#+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/black"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/my_toolbar">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:isScrollContainer="false">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/footer_layout"
android:layout_marginTop="#dimen/dp_10"
android:background="#drawable/bg_add_buddy_fragment"
android:visibility="visible" />
</LinearLayout>
</ScrollView>
<include
android:id="#+id/footer_layout"
layout="#layout/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:layout_alignParentBottom="true" />
</RelativeLayout>
</RelativeLayout>
You have a RecyclerView in a ScrollView. Remove the parent ScrollView.
Add android:windowSoftInputMode="adjustNothing" to AndroidManifest.xml for this activity.
Replace your ScrollView with **NestedScrollView** in your XML Layout and define
android:windowSoftInputMode="ajustPan|stateAlwaysHidden" in your manifest in particular activity
Add below code to your manifest
<activity android:name=".YourActivity"
android:windowSoftInputMode="adjustPan|stateHidden"/>
I have own EditText in layout, I use it to search. but select the text of into EditText bug in top of my layout.
please see below photo to understand my mean
layout code :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:background="#000"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.tellfa.smsbox.Search_page">
<include
android:id="#+id/app_bar"
layout="#layout/app_bar" />
<EditText
android:id="#+id/search_bar_text"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:background="#color/primaryColor"
android:gravity="right|center_vertical"
android:hint="#string/search_page_hing"
android:maxLength="25"
android:maxLines="1"
android:singleLine="true"
android:textColor="#color/search_hint"
android:textColorHint="#color/hint_foreground_material_dark"
android:textSize="20sp"
android:windowSoftInputMode="stateAlwaysHidden" />
Appbar code :
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/primaryColor"
app:popupTheme="#style/ThemeOverlay.AppCompat.Dark"
app:theme="#style/MyCustomToolbarTheme"
android:paddingTop="15dp"
>
how to fix it or change top of layout background ?
Update your layout like:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent" >
..
</RelativeLayout>
Also make sure that your project uses style
Theme.AppCompat.Light.NoActionBar
Tell me if it works for you!