Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/214.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何更改android软键盘按键的背景色?_Android_Keyboard_Android Softkeyboard - Fatal编程技术网

如何更改android软键盘按键的背景色?

如何更改android软键盘按键的背景色?,android,keyboard,android-softkeyboard,Android,Keyboard,Android Softkeyboard,我正在Android上实现自定义键盘。我刚刚阅读了“developer.android.com”上的文档,看到了软键盘的示例。我所能做的就是改变键盘背景,改变按钮的位置,将keyIcon而不是keyLabel设置为key 但我还是不能改变钥匙的背景和颜色 请编写一些XML或源代码的示例代码。谢谢 我更改背景的示例: public class GBInput extends InputMethodService implements KeyboardView.OnKeyboardActio

我正在Android上实现自定义键盘。我刚刚阅读了“developer.android.com”上的文档,看到了软键盘的示例。我所能做的就是改变键盘背景,改变按钮的位置,将keyIcon而不是keyLabel设置为key

但我还是不能改变钥匙的背景和颜色

请编写一些XML或源代码的示例代码。谢谢

我更改背景的示例:

    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;
        }
    ...
    }
我需要这样的东西:


所有按钮的图像-这不是个好主意,所以我想找出更好的问题。

将这行代码添加到input.xml中

android:keyBackground="@drawable/samplekeybackground"
因此,您的input.xml最终应该与此类似

<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"
    />

如果你已经有了一个绘图工具,可以使用great,否则这里有一个示例键背景绘图工具,它将产生类似于你的示例图像的结果

    <?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。 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> 

和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:keyTextColor=“#000000”


这将由您的图形专家管理,因为这是一个关键图标,只是我猜您的问题有点太宽泛了;你能发布一些你编辑过的XML吗?有什么不符合预期?在我的问题中添加了更多信息。@ridoy,你的链接上没有解决方案!答案很好,但是键盘上的按键颜色是白色的。如何更改颜色?在drawable/normal.xml中找到>
将#FFFFFF更改为您想要的颜色。有关详细信息,请参阅。这仅适用于键盘视图级别,如果您试图为特定键设置不同的颜色,则不适用。有没有关于如何在键盘xml中实现的想法?我需要在单击按钮后使其保持黄色
<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"
    android:keyTextColor="#000000"
    />