自定义软键盘布局尺寸

3

I made a custom soft keyboard.

XML file:

<?xml version="1.0" encoding="UTF-8"?>
<android.inputmethodservice.KeyboardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/keyboard"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:background="#1B0A33"
    android:keyBackground="@drawable/pexeso_keyboard_key"
/>

Java源代码文件:

public class PexesoKeyboard extends InputMethodService implements
        KeyboardView.OnKeyboardActionListener {

        private KeyboardView kv;
        private Keyboard keyboard;
        private boolean caps = false;

        @Override
        public View onCreateInputView() {
            kv = (KeyboardView)getLayoutInflater().inflate(R.layout.pexeso_keyboard, null);
            keyboard = new Keyboard(this, R.xml.pexeso_keyboard_map);
            kv.setKeyboard(keyboard);
            kv.setPadding(10, 10, 10, 10);
            kv.setOnKeyboardActionListener(this);
            kv.invalidateAllKeys();
                kv.setPreviewEnabled(false);
                return kv;
            }


             ..
             ..
             ..
}

现在它看起来是这样的:

enter image description here

我希望它看起来像这样:

并且我想让它看起来像这样: enter image description here

如何调整布局以及什么是最佳解决方案?欢迎提出所有想法。
1个回答

1

这比我预想的要容易。我只是编辑了布局 - 在相对布局中添加了键盘视图。然后在onCreateInputView()中添加了LayoutInflater。

Java

@Override
    public View onCreateInputView() {

        LayoutInflater li = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View v = li.inflate(R.layout.pexeso_keyboard_layout, null);
        kvw = (KeyboardView)v.findViewById(R.id.keyboard);
        keyboard = new Keyboard(this, R.xml.pexeso_keyboard_map);
        kvw.setKeyboard(keyboard);
        kvw.setOnKeyboardActionListener(this);
        kvw.setPreviewEnabled(false);
        keyboardMinWidth = kvw.getKeyboard().getMinWidth();
        displayWidth = getApplication().getResources().getDisplayMetrics().widthPixels;
        kvw.invalidateAllKeys();
        return v;
    }

布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="@color/pxs_keyboard_background"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:gravity="center_vertical|bottom">

    <android.inputmethodservice.KeyboardView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/keyboard"
        android:layout_margin="35dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/pxs_keyboard_background"
        android:keyBackground="@drawable/pexeso_keyboard_key"
        android:layout_centerHorizontal="true">
    </android.inputmethodservice.KeyboardView>

</RelativeLayout>

预览

How it looks


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接