Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.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_Xml_Android Layout_Android Softkeyboard - Fatal编程技术网

特殊按键的键盘背景-android键盘

特殊按键的键盘背景-android键盘,android,xml,android-layout,android-softkeyboard,Android,Xml,Android Layout,Android Softkeyboard,我在软键盘的基础上开发了Android键盘。现在设计选择器中使用的键盘并更改键盘背景。现在,除了单键和活动键外,所有键都可以正常工作。它们显示为标准键:( 这是我的slector代码: <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_single=

我在软键盘的基础上开发了Android键盘。现在设计选择器中使用的键盘并更改键盘背景。现在,除了单键和活动键外,所有键都可以正常工作。它们显示为标准键:(

这是我的slector代码:

<?xml version="1.0" encoding="utf-8"?>
<selector
  xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_single="true" android:state_pressed="true" android:drawable="@drawable/btn_keyboard_key_dark_pressed_holo" />
    <item android:state_single="true" android:drawable="@drawable/btn_keyboard_key_dark_normal_holo" />
    <item android:state_active="true" android:state_pressed="true" android:drawable="@drawable/btn_keyboard_key_dark_pressed_holo" />
    <item android:state_active="true" android:drawable="@drawable/btn_keyboard_key_dark_active_holo" />
    <item android:state_checkable="true" android:state_checked="true" android:state_pressed="true" android:drawable="@drawable/btn_keyboard_key_dark_pressed_on_holo" />
    <item android:state_checkable="true" android:state_pressed="true" android:drawable="@drawable/btn_keyboard_key_dark_pressed_off_holo" />
    <item android:state_checkable="true" android:state_checked="true" android:drawable="@drawable/btn_keyboard_key_dark_normal_on_holo" />
    <item android:state_checkable="true" android:drawable="@drawable/btn_keyboard_key_dark_normal_off_holo" />
    <item android:state_pressed="true" android:drawable="@drawable/btn_keyboard_key_light_pressed_holo" />
    <item android:drawable="@drawable/btn_keyboard_key_light_normal_holo" />
</selector>

解决方案:

经过多次尝试,我找到了解决问题的办法! 在原始的键盘类中,单个/活动的可绘制状态是不确定的。因此,我们需要做的是重写该类

怎么做? 如果您的键盘基于软键盘,我们有一个扩展键盘的拉丁键盘类。 如果你没有这个类,创建它! 现在在这个类中,我们有一个LatinKey静态类,它扩展了Keyboard.Key

现在,如何编写代码: 这是LatinKey类代码:

静态类密钥扩展密钥{
公钥(Resources res、行父级、int x、int y、XmlResourceParser){
super(res、parent、x、y、parser);
}
私有最终静态int[]密钥\状态\正常\开启={
android.R.attr.state\u可检查,
android.R.attr.state\u已选中
};
私有最终静态int[]键\u状态\u按下\u ON={
android.R.attr.state_按下,
android.R.attr.state\u可检查,
android.R.attr.state\u已选中
};
私有最终静态int[]密钥\状态\正常\关闭={
android.R.attr.state\u可检查
};
私有最终静态int[]键\状态\按下\关闭={
android.R.attr.state_按下,
android.R.attr.state\u可检查
};
私有最终静态int[]键\状态\函数={
android.R.attr.state\u single
};
私有最终静态int[]键\状态\函数\按下={
android.R.attr.state_按下,
android.R.attr.state\u single
};
私有最终静态int[]密钥\状态\正常={
};
私有最终静态int[]键\状态\按下={
android.R.attr.state\u按下
};
@凌驾
public int[]getCurrentDrawableState(){
int[]状态=键状态正常;
如果(打开){
如果(按下){
状态=按键\状态\按下\打开;
}否则{
状态=按键状态正常开启;
}
}否则{
如果(粘性){
如果(按下){
状态=按键\状态\按下\关闭;
}否则{
状态=按键\状态\正常\关闭;
}
}else if(修饰符){
如果(按下){
状态=按键\状态\功能\按下;
}否则{
状态=键状态函数;
}
}否则{
如果(按下){
状态=按键状态按下;
}
}
}
返回状态;
}
}
除了另一个原始状态之外,我添加了STATE_函数和STATE_函数。 然后我重写了getCurrentDrawableState方法,并向该方法添加了新的状态。之后,如果键是修饰符,它将是STATE_函数,并使用drawableStateList中的STATE_single

现在在键盘上:

公共类拉丁键盘扩展键盘{
公共拉丁键盘(上下文上下文,int-xmlLayoutResId){
super(上下文,xmlLayoutResId);
//TODO自动生成的构造函数存根
}
公共拉丁键盘(上下文,int-layoutTemplateResId,
字符序列字符、int列、int水平填充){
超级(上下文、layoutTemplateResId、字符、列、水平填充);
}
@凌驾
受保护的密钥createKeyFromXml(资源res、行父级、int x、int y、,
XmlResourceParser(语法分析器){
Key Key=新的拉丁键(res、父、x、y、解析器);
返回键;
}
静态类LatinKey扩展了键盘{
//拉丁键代码。。。
}
}

我们重写了createKeyFromXml并返回了新的LatinKey,现在在主键盘类上使用新的LatinKeyboard类并享受:)

谢谢。这正是我想要的。