如何更改按键的颜色KeyboardView类自定义键盘的Andr​​oid [英] How to change color of keys in KeyboardView Class in custom keyboard android

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

问题描述

我在自定义键盘应用程序工作,我需要为KeyboardView类键或背景色设置不同的主题,并在onCreateInputView()在SoftKeyboard获取密钥色彩延伸InputMethodService类,但我没有得到如何根据键获取特定的键code,所以我可以改变颜色或特定按键的背景

I am Working on 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 but 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());

如果您已经做了它,你需要的是设置一个不同的背景,特殊键。也许解决我的问题,我写将帮助您:<一href=\"http://stackoverflow.com/a/18354298/2683898\">http://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: http://stackoverflow.com/a/18354298/2683898

祝您好运! :)

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

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