0

I'm working on a soft keyboard project for Android, and wanted to add some LinearLayouts at the top of my KeyboardView. I've used this question to put the layouts, but when I run the project, only the KeyboardView appears. I've edited the layout height and width, but nothing works. Where does the problem come from?

Here's my code:

keyboardview.xml:

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:background="#212121"
    android:id="@+id/linear1">
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="50dp"
    android:layout_width="match_parent"
    android:orientation="horizontal">
    <ImageView
        android:id="@+id/keyboard1"
        android:layout_height="50dp"
        android:layout_width="50dp"
        android:src="@drawable/ic_keyboard"
        android:gravity="center"
        android:foreground="?android:attr/selectableItemBackground"
        />
    <ImageView
        android:id="@+id/keyboard2"
        android:layout_height="50dp"
        android:layout_width="50dp"
        android:src="@drawable/ic_keyboard"
        android:gravity="center"
        android:foreground="?android:attr/selectableItemBackground"
        />
    <TextView
        android:id="@+id/keyboard3"
        android:layout_height="50dp"
        android:layout_width="50dp"
        android:text="K"
        android:textSize="11dp"
        android:textColor="#AAAAAA"
        android:gravity="center"
        android:foreground="?android:attr/selectableItemBackground"
        />
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:gravity="center|end">
        <ImageView
            android:id="@+id/backcursor"
            android:layout_height="50dp"
            android:layout_width="50dp"
            android:src="@drawable/ic_backcursor"
            android:gravity="center"
            android:foreground="?android:attr/selectableItemBackground"
            />
        <ImageView
            android:id="@+id/nextcursor"
            android:layout_height="50dp"
            android:layout_width="50dp"
            android:src="@drawable/ic_nextcursor"
            android:gravity="center"
            android:foreground="?android:attr/selectableItemBackground"
            />
    </LinearLayout>
</RelativeLayout>
<android.inputmethodservice.KeyboardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/keyboard"
    android:keyPreviewLayout="@layout/keyboard_preview"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:keyBackground="@drawable/key_background"
    android:keyTextColor="#FFFFFF"
    android:background="#212121"/>
    </LinearLayout>

Java class:

@Override
public View onCreateInputView() {
    final View root = getLayoutInflater().inflate(R.layout.keyboardview, null, false);
    keyboardView = (KeyboardView) root.findViewById(R.id.keyboard); 
    ImageView keyboard1 = (ImageView) root.findViewById(R.id.keyboard1);
    ImageView keyboard2 = (ImageView) root.findViewById(R.id.keyboard2);
    TextView keyboard3 = (TextView) root.findViewById(R.id.keyboard3);
    ImageView backcursor = (ImageView) root.findViewById(R.id.backcursor);
    ImageView nextcursor = (ImageView) root.findViewById(R.id.nextcursor);
    keyboard = new Keyboard(this, R.xml.keys_layout);
    keyboardView.setKeyboard(keyboard);
    keyboardView.setOnKeyboardActionListener(this);
    caps = true;
Vincent
  • 159
  • 1
  • 2
  • 9
  • Can you see the `50dp` space where those should be? What are you returning at the end of `onCreateInputView()`? Please post the complete method. – Mike M. Nov 27 '19 at 00:24
  • don't know if it will help, but remove xmlns:android="http://schemas.android.com/apk/res/android" from the internal relativelayout – Ricardo A. Nov 27 '19 at 12:55

0 Answers0