如何在自定义Android键盘中更改KeyboardView类中键的颜色? [英] How to change color of keys in KeyboardView Class in custom Android keyboard?

查看:654
本文介绍了如何在自定义Android键盘中更改KeyboardView类中键的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用自定义键盘"应用程序.我需要在KeyboardView类中为键或背景色设置不同的主题,并在SoftKeyboard扩展InputMethodService类的onCreateInputView()处获取键色.

I am working on a Custom Keyboard App. I need to set different themes for keys or background color in KeyboardView class and get key color at onCreateInputView() in SoftKeyboard extends InputMethodService Class.

但是我没有得到如何根据键码获取特定键的信息,所以我可以更改特定键的颜色或背景.

However I am not getting how to get particular key according to keycode so I can change color or background of particular key.

推荐答案

在任何不同的输入布局上,请使用android:keyBackground =".."

On any diffrent input layout use android:keyBackground=".."

示例:

input.xml:

input.xml:

<com.example.KeyboardView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/keyboard"
        android:layout_alignParentBottom="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:keyBackground="@drawable/blue_key"
        />

input1.xml:

input1.xml:

<com.example.KeyboardView
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/keyboard"
            android:layout_alignParentBottom="true"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:keyBackground="@drawable/red_key"
            />

然后使用OnCreateInputView方法:

then on OnCreateInputView method:

@Override public View onCreateInputView() {
    if(theme == 1)
        mInputView = (KeyboardView) getLayoutInflater().inflate(R.xml.input , null);
    else
        mInputView = (KeyboardView) getLayoutInflater().inflate(R.xml.input1 , null);
    mInputView.setOnKeyboardActionListener( this);
    mInputView.setKeyboard(mQwertyKeyboard);
    mComposing.setLength(0);
    return mInputView;
}

,然后在onStartInput方法的末尾添加以下内容:

and on the end of the method onStartInput add this:

setInputView(onCreateInputView());

如果您已经完成此操作,则需要为特殊键设置不同的背景.也许我写的我的问题的解决方案可以为您提供帮助: https://stackoverflow.com/a/18354298/2683898

If you've already done it and what you need is to set a different background to special keys. Maybe the solution to my problem that I wrote will help you: https://stackoverflow.com/a/18354298/2683898

祝你好运! :)

这篇关于如何在自定义Android键盘中更改KeyboardView类中键的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆