I'm trying to figure out how to use android:windowSoftInputMode="adjustResize"
to prevent the soft keyboard from covering a list of EditText items. Here is a simple app with a single layout and activity class that reproduces my issue:
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContentView(R.layout.activity_main)
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
insets
}
}
}
Layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=";
xmlns:app=";
xmlns:tools=";
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:id="@+id/mytitle"
android:layout_width="match_parent"
android:layout_height="40dp"
android:text="Static Header"
android:gravity="center_horizontal"
android:textSize="24sp">
</TextView>
<ScrollView
android:id="@+id/nested_scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
<EditText
android:layout_width="match_parent"
android:text="item"
android:inputType="textLongMessage"
android:layout_marginBottom="10dp"
android:layout_height="wrap_content">
</EditText>
...
repeat 39 more edit texts
...
</LinearLayout>
</ScrollView>
</LinearLayout>
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=";
xmlns:tools=";>
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Shop2"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:windowSoftInputMode="adjustResize"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
See image here
In the linked image, I've clicked an EditText near the bottom of the screen, and even though it appeared to receive focus correctly, the soft keyboard is still covering the input and it's hard to see where you're typing. I'd like the layout to resize itself above the keyboard.
I have a static header which I want to prevent being bumped off the screen by panning when the keyboard appears, that's why I've chosen adjustResize.
I'm open to using a ListView or other list container view, but that's slightly tangential to my issue which is I would like to understand why this simpler setup doesn't behave as I expect.
I'm trying to figure out how to use android:windowSoftInputMode="adjustResize"
to prevent the soft keyboard from covering a list of EditText items. Here is a simple app with a single layout and activity class that reproduces my issue:
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContentView(R.layout.activity_main)
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
insets
}
}
}
Layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android/apk/res/android"
xmlns:app="http://schemas.android/apk/res-auto"
xmlns:tools="http://schemas.android/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:id="@+id/mytitle"
android:layout_width="match_parent"
android:layout_height="40dp"
android:text="Static Header"
android:gravity="center_horizontal"
android:textSize="24sp">
</TextView>
<ScrollView
android:id="@+id/nested_scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
<EditText
android:layout_width="match_parent"
android:text="item"
android:inputType="textLongMessage"
android:layout_marginBottom="10dp"
android:layout_height="wrap_content">
</EditText>
...
repeat 39 more edit texts
...
</LinearLayout>
</ScrollView>
</LinearLayout>
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android/apk/res/android"
xmlns:tools="http://schemas.android/tools">
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Shop2"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:windowSoftInputMode="adjustResize"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
See image here
In the linked image, I've clicked an EditText near the bottom of the screen, and even though it appeared to receive focus correctly, the soft keyboard is still covering the input and it's hard to see where you're typing. I'd like the layout to resize itself above the keyboard.
I have a static header which I want to prevent being bumped off the screen by panning when the keyboard appears, that's why I've chosen adjustResize.
I'm open to using a ListView or other list container view, but that's slightly tangential to my issue which is I would like to understand why this simpler setup doesn't behave as I expect.
Share Improve this question asked Feb 17 at 16:29 lrouleaulrouleau 11 Answer
Reset to default 0I was able to get this working by padding out the keyboard inset. Now the layout resizes above the keyboard:
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
val ime = insets.getInsets(WindowInsetsCompat.Type.ime())
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom + ime.bottom)
insets
}
This solution looks reasonable, but I'd appreciate any alternative solutions or additional advice as I'm new to android development. My initial impression from reading various docs was that I wouldn't need to do this manual padding adjustment with android:windowSoftInputMode="adjustResize"
set.