Android 如何创建复杂的键盘样式(例如包含列表视图)?
我在谷歌上搜索了很多,但仍然没有找到答案Android 如何创建复杂的键盘样式(例如包含列表视图)?,android,keyboard,Android,Keyboard,我在谷歌上搜索了很多,但仍然没有找到答案 <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android" > <item android:state_pressed="true" android:drawable="@drawable/bbg_pressed"></item> <
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" android:drawable="@drawable/bbg_pressed"></item>
<item android:state_focused="true" android:drawable="@drawable/bbg_selected"></item>
<item android:drawable="@drawable/bbg_normal"></item>
</selector>
我想创建如下键盘样式:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" android:drawable="@drawable/bbg_pressed"></item>
<item android:state_focused="true" android:drawable="@drawable/bbg_selected"></item>
<item android:drawable="@drawable/bbg_normal"></item>
</selector>
您可以看到,最左边的键位于一个特殊的列中,当我的手指上下移动时,它可以滚动
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" android:drawable="@drawable/bbg_pressed"></item>
<item android:state_focused="true" android:drawable="@drawable/bbg_selected"></item>
<item android:drawable="@drawable/bbg_normal"></item>
</selector>
我应该如何编写键盘布局并用java代码将其膨胀?谢谢public View onCreateInputView返回您可以创建的任何类型的视图
LayoutInflater li = getLayoutInflater();
View v = li.inflate(R.layout.myview, null);
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" android:drawable="@drawable/bbg_pressed"></item>
<item android:state_focused="true" android:drawable="@drawable/bbg_selected"></item>
<item android:drawable="@drawable/bbg_normal"></item>
</selector>
其中,在InputMethodService中定义了GetLayoutFlater
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" android:drawable="@drawable/bbg_pressed"></item>
<item android:state_focused="true" android:drawable="@drawable/bbg_selected"></item>
<item android:drawable="@drawable/bbg_normal"></item>
</selector>
注意还有
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" android:drawable="@drawable/bbg_pressed"></item>
<item android:state_focused="true" android:drawable="@drawable/bbg_selected"></item>
<item android:drawable="@drawable/bbg_normal"></item>
</selector>
-更新:我正在粘贴一部分xml,它与原始问题无关,但与状态列表下面的注释中提出的问题有关,可用于作为按钮的布局:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" android:drawable="@drawable/bbg_pressed"></item>
<item android:state_focused="true" android:drawable="@drawable/bbg_selected"></item>
<item android:drawable="@drawable/bbg_normal"></item>
</selector>
drawable/button_background.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" android:drawable="@drawable/bbg_pressed"></item>
<item android:state_focused="true" android:drawable="@drawable/bbg_selected"></item>
<item android:drawable="@drawable/bbg_normal"></item>
</selector>
你可以在android上使用LinearLayout或任何其他视图作为按钮:clickable=trueyes,我做了。单击按钮时,将正确触发单击事件。但是按钮的背景一点也没有改变。我记得,button小部件应该有一个默认的状态列表。你知道为什么吗?我想,因为这就是改变背景的方式。请参阅更新中的示例代码。感谢您的帮助!