如何更改关键的背景色为Android的软键盘? [英] How to change background color of key for android soft keyboard?

查看:781
本文介绍了如何更改关键的背景色为Android的软键盘?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实现在Android定制的键盘。刚才我看到文档的developer.android.com,看过样品与软键盘。我能 - 它单曲改变键盘的背景,按钮变化的位置,设置keyIcon而不是keyLabel关键

I am implementing custom keyboard on Android. I have just read documentation on "developer.android.com" and seen sample with soft keyboard. All I can - it`s to change keyboard background, change placement of buttons, set keyIcon instead of keyLabel to key.

但我还是无法改变key`s背景和颜色。

But I still can not change key`s background and color.

请编写XML或源的一些示例code。谢谢!

Please write some sample code of XML or source. Thanks!

我的例子,我改变背景:

My sample where I change background:

    public class GBInput extends InputMethodService implements KeyboardView.OnKeyboardActionListener{
    ...
    private GBKeyboardView mInputView;
    @Override
        public View onCreateInputView() {
            mInputView = (GBKeyboardView) getLayoutInflater().inflate(R.layout.input, null);
            mInputView.setOnKeyboardActionListener(this);
            mInputView.setKeyboard(mQwertyKeyboard);
            mInputView.setBackgroundResource(R.color.keyboard_background);
            return mInputView;
        }
    ...
    }

和我需要类似的东西:

And I need something like that :

对于所有的按钮图像 - 它的坏主意,所以我想找到更好的问题

Images for all buttons - its bad idea, so I want to find better issue.

推荐答案

添加此行的code您input.xml中

Add this line of code to your input.xml

android:keyBackground="@drawable/samplekeybackground"

所以,你input.xml中应该结束了寻找与此类似。

So your input.xml should end up looking similar to this.

<com.example.keyboard.LatinKeyboardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/keyboard"
    android:layout_alignParentBottom="true"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:keyPreviewLayout="@layout/input_key_preview"
    android:keyBackground="@drawable/samplekeybackground"
    />

如果你已经有了一个绘制使用大,否则这里是一个示例的关键背景的绘制,这将产生像你的榜样的图像效果。

If you already have a drawable to use great otherwise here is a sample key background drawable that will produce results like your example image.

    <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- Non focused states -->
    <item
        android:state_focused="false"
        android:state_selected="false"
        android:state_pressed="false"
        android:drawable="@drawable/normal" />
    <!-- Pressed state -->
    <item
        android:state_pressed="true"
        android:drawable="@drawable/pressed" /></selector>

如果你想要的一切在XML中,您可以使用形状XML的如下所示。 绘制/ normal.xml

If you want everything in xml you can use shape xml's like the following. drawable/normal.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
  <stroke android:width="4dp" android:color="#000000" /> 
  <solid android:color="#FFFFFF"/> 
</shape> 

和绘制/ pressed.xml

and drawable/pressed.xml

<?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"> 
      <stroke android:width="4dp" android:color="#A3D9F3" /> 
      <solid android:color="#4ABCE8"/> 
    </shape>

这篇关于如何更改关键的背景色为Android的软键盘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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