您好我实现了一个SearchView,它在ListView中显示结果。我面临的问题是我有一个自定义键盘,我的Listview重叠在keyboardView上,所以我无法按键盘上的某些键。我想要实现的是我的Listview将显示在KeyboardView.Here是我的布局文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/basic_bg" >
<android.inputmethodservice.KeyboardView
android:id="@+id/keyboardView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:visibility="gone" />
<SearchView
android:id="@+id/searchView"
android:layout_width="400dp"
android:layout_height="40dp"
android:layout_alignParentTop="true"
android:layout_alignRight="@+id/textView3"
android:layout_marginLeft="49dp"
android:layout_marginTop="25dp"
android:layout_toRightOf="@+id/imageViewUp"
android:background="@drawable/delete_bg_5line"
android:ems="10"
android:hint="Destination Input Text"
android:textColor="#87CEFA" >
</SearchView>
<ListView
android:id="@+id/main_list_View"
android:layout_width="450dp"
android:layout_height="235dp"
android:layout_alignLeft="@+id/searchView"
android:layout_below="@+id/searchView"
android:listSelector="@android:color/transparent"
android:scrollbars="none" >
</ListView>
</RelativeLayout>
我也希望在用户浏览ListView时隐藏自定义键盘 和更改键盘可见性的代码
searchtextView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method st4ub
toggleKeyboardVisibility(searchtextView);
}
private void toggleKeyboardVisibility(
AutoCompleteTextView searchViewWidget) {
KeyboardView keyboardView = (KeyboardView) findViewById(R.id.keyboardView);
int visibility = keyboardView.getVisibility();
switch (visibility) {
case View.VISIBLE:
keyboardView.setVisibility(View.GONE);
break;
case View.GONE:
case View.INVISIBLE:
keyboardView.setVisibility(View.VISIBLE);
searchtextView = searchViewWidget;
break;
}
}
});
我想要做的另一件事是更改我的键盘键的背景。我无法做到这一点我尝试将android:keyIcon属性添加到每个键但是它不起作用当我使用这个属性时,只有预览背景图像发生了变化。我该怎样做呢。
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
android:horizontalGap="0px"
android:keyBackground="@drawable/custom_keyboard_press_onekey"
android:keyWidth="10%p"
android:verticalGap="0px" >
<Row>
<Key
android:codes="1"
android:iconPreview="@drawable/custom_keyboard_press_onekey"
android:isRepeatable="true"
android:keyEdgeFlags="left"
android:keyIcon="@drawable/custom_keyboard_press_onekey"
android:keyLabel="1" />
</Row>
</Keyboard>
这就是我实例化键盘的方式
final KeyboardView keyboardView = (KeyboardView) findViewById(R.id.keyboardView);
Keyboard keyboard = new Keyboard(this, R.layout.keyboard);
keyboardView.setKeyboard(keyboard);
keyboardView.setEnabled(true);
keyboardView.setPreviewEnabled(true);
keyboardView.setOnKeyboardActionListener(this);
有人可以指导我出错的地方或建议我该怎么做。谢谢你的帮助。
答案 0 :(得分:1)
要在列表视图上方查看键盘,请将布局更改为
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/basic_bg" >
<SearchView
android:id="@+id/searchView"
android:layout_width="400dp"
android:layout_height="40dp"
android:layout_alignParentTop="true"
android:layout_alignRight="@+id/textView3"
android:layout_marginLeft="49dp"
android:layout_marginTop="25dp"
android:layout_toRightOf="@+id/imageViewUp"
android:background="@drawable/delete_bg_5line"
android:ems="10"
android:hint="Destination Input Text"
android:textColor="#87CEFA" >
</SearchView>
<ListView
android:id="@+id/main_list_View"
android:layout_width="450dp"
android:layout_height="235dp"
android:layout_alignLeft="@+id/searchView"
android:layout_below="@+id/searchView"
android:listSelector="@android:color/transparent"
android:scrollbars="none" >
</ListView>
<android.inputmethodservice.KeyboardView
android:id="@+id/keyboardView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:visibility="gone" />
</RelativeLayout>