Reputation: 17
I am developing a Android Soft Keyboard. I want to create a layout above the Soft Keyboard. Whenever keyboard show on the screen the layout must visible.
You can easily understand my idea by seeing this image.
Upvotes: 0
Views: 1066
Reputation: 4060
As mentioned by Jawad Ahmend in the comments, it's possible to attach the layout to the top of the keyboard by attaching it to the parent bottom using ConstraintLayout
. You'd essentially need to do the following steps:
windowSoftInputMode
as adjustResize
for your activity in the manifest.
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:windowSoftInputMode="adjustResize"
android:theme="@style/AppTheme.NoActionBar">
visibility
to gone and add a layout constraint attaching it's bottom to the bottom of the parent.
<LinearLayout android:id="@+id/layout_B"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone">
KeyboardVisibilityEvent
library. Add the following line to your app's build.gradle and sync it.
implementation 'net.yslibrary.keyboardvisibilityevent:keyboardvisibilityevent:2.3.0'
KeyboardVisibilityEvent.setEventListener(this) { keyboardIsOpen ->
layout_B.visibility = if (keyboardIsOpen) {
View.VISIBLE
} else {
View.GONE
}
}
Upvotes: 1
Reputation: 93561
If you're writing the keyboard, its easy. Just override onCreateInputView to return the view you want. This can easily be a linear layout with your extra views and the keyboard itself in it.
The bigger problem I see is you have an EditText in there. That's not going to work. Tapping on the EditText is going to break the InputConnection to the actual app and cause... unknown weird behavior. I'm not even sure if the behavior will be defined across different OS versions. It may cause the keyboard to immediately hide. It may cause the keyboard to just stop working at all. The OS isn't meant for that.
Upvotes: 0