我正在
@L_502_0@上实现自定义键盘.我刚刚阅读了“developer.android.com”上的文档,并看到了使用软键盘的示例.我只能 – 改变键盘背景,改变按钮位置,将keyIcon而不是keyLabel设置为键.
但我仍然无法改变关键的背景和颜色.
我改变背景的样本:
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; } ... }@H_502_9@我需要这样的东西:
所有按钮的图像 – 它的坏主意,所以我想找到更好的问题.
解决方法
将此行代码添加到input.xml
android:keyBackground="@drawable/samplekeybackground"@H_502_9@所以你的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" />@H_502_9@如果你已经有一个drawable使用很好,否则这里有一个示例关键背景drawable将产生像你的示例图像.
<?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>@H_502_9@如果你想要xml中的所有内容,你可以使用如下形状xml.
绘制/ 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>@H_502_9@和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>@H_502_9@