Push Up Content When Clicking in Edit Text

Push up content when clicking in edit text

Actually if you want your entire layout pan up than you should use :

SOFT_INPUT_ADJUST_PAN

meaning:

getActivity().getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

this will keep the keyboard closed and when opened it'll push your entire activity up.

how to push edittext up when keyboard appears

try this

 <activity
android:name="com.ex.YourActivity"
android:label="@string/app_name"
android:windowSoftInputMode="adjustPan" >
</activity>

Push up content except some view when keyboard shown

With the new feature of WindowInsetsCompat which help detecting keyboard visibility easily (I follow answer here https://stackoverflow.com/a/63517673/5381331).

Instead of using windowSoftInputMode=adjustPan for less complex like before, now I can solve this problem by combine windowSoftInputMode=adjustResize with WindowInsetsCompat

ViewCompat.setOnApplyWindowInsetsListener(root) { v, insets ->
val isKeyboardVisible = insets.isVisible(WindowInsetsCompat.Type.ime())

if (isKeyboardVisible) {
// Hide some view when keyboard visible
} else {
// Show it again here
}
}

AndroidManifest

<activity android:name=".activity_name"
android:windowSoftInputMode="adjustResize"> // all content will push to above keyboard then we able to scroll to see whole content

</activity>

Android Title bar gets pushed up when edit text content increases

I managed to solve this issue by putting edittext in scrollview and replacing adjustPan with adjustSize in the manifest. This is the final working layout

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rl_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background">
<EditText
android:id="@+id/hidden_edit_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:imeOptions="flagNoExtractUi"
android:inputType="textMultiLine"
android:paddingLeft="10sp"
android:paddingRight="5sp"
android:paddingTop="5sp"
android:singleLine="false"
android:textSize="25sp" >
</EditText>
</ScrollView>


Related Topics



Leave a reply



Submit