3

What is the simplest way to attach a layout defined in xml at the top of Android soft keyboard. This view should only appear when the keyboard appears.

Daniel L.
  • 4,820
  • 8
  • 34
  • 59

4 Answers4

0

I think the best way is to detect when the keyboard appears and then attach view to the bottom of the screen (it will be above the keyboard after resizing all layout).

dilix
  • 3,510
  • 3
  • 27
  • 53
  • The problem is that I want the keyboard to float above my layout and won't change it (i'm using `android:windowSoftInputMode="adjustPan"`) – Daniel L. Feb 06 '13 at 09:49
  • 1
    Than i think it's quite impossible to do that (i don't know/imagine a way to do this) – dilix Feb 06 '13 at 10:00
0

I think that this post has many to do with this other: How to draw view on top of soft keyboard like WhatsApp? and there is a couple of solutions for this problem.

Community
  • 1
  • 1
Parmaia
  • 1,082
  • 1
  • 13
  • 27
0

I think the cleaner way to do this.

  1. Define a layout resource file to use as your custom view

  2. Create a method which inflates this layout resource file and return it as a view: Code Snippet

    public View returnPayKeyView(){
    View simpleView = getLayoutInflater().inflate(R.layout.simpleresource,null);

    return simpleView;

    }

  3. Set this returned view as the candidates using the setCandidatesView Method

The returned view will show above your keyboard, using the inflated xml layout resource.

vofili
  • 81
  • 8
0

One approach is to wrap your usual view layout in a FrameLayout and put the bit you want above the keyboard inside the frame along with your other view layout with a layout gravity of bottom.

My layout was along these lines:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <!-- all your stuff... -->

        </LinearLayout>

    </ScrollView>

    <LinearLayout
        android:id="@+id/stuffAboveKeyboardLayout"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:layout_gravity="bottom"
        android:orientation="horizontal"
        android:background="#DDD">

        <!-- stuff above keyboard... -->

    </LinearLayout>

</FrameLayout>

The downside is that it will show even when the keyboard is hidden - but it ought to be possible to show / hide the view when the keyboard shows / hides: How do I Detect if Software Keyboard is Visible on Android Device?

mrrrk
  • 1,746
  • 16
  • 13