Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't my layout move up enough with "adjustPan"?

I had some issues using adjustPan in my app, as it is not working as it is supposed to do. Some other users also experienced this problem, so I think it's important to share this issue (Layout doesn't move up enough when clicking EditText).

Note: I am using Android Studio and I'm using an "Instant App", so the location of the files are going to be a bit different.

When I use adjustPan in my layout, my activity does not move up enough to the point where the EditText appears above the Soft Keyboard (See Image For Details). The same result still appears no matter if you use it in a Manifest file or a Java file.

Not only that, but the weirdest part is that Status Bar becomes transparent and the dark blue bar which is supposed to go behind the notification icons goes down a little bit (See Image For Details).

Screenshot of issue

I have tried making several attempts of solving this issue, like using adjustResize and setOnTouchListener but both of these answers that I received didn't solve this issue.

I still can't figure out the cause of this issue, so any answers or comments regarding how to discover why this issue is happening is also fine.

Here is some of my code:

Manifest File:

<activity
        android:name=".Input_Activity"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="adjustPan" />

Java File:

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.WindowManager;

public class Input_Activity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_input__activity);

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

XML File:

<android.support.constraint.ConstraintLayout 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=".Input_Activity">

<EditText
    android:layout_width="214dp"
    android:layout_height="wrap_content"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginBottom="8dp"
    android:inputType="number|numberDecimal"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.585"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.725" />

All feedback would be appreciated.

like image 461
Devealte Avatar asked Oct 16 '22 07:10

Devealte


1 Answers

create an object like InputMethodManager methodManager at class level.
add these lines to your onCreate() method,

methodManager = (InputMethodManager) this.getSystemService(this.INPUT_METHOD_SERVICE);
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

and in your onClick() method, show keyboard like,

methodManager.toggleSoftInputFromWindow(
    your_view_name.getApplicationWindowToken(),
    InputMethodManager.SHOW_FORCED, 0);  

If this word getApplicationWindowToken throws an error then replace it with getWindowToken
hope it helps.

like image 171
Viraj S Avatar answered Nov 15 '22 12:11

Viraj S