1

嗨,我实现了一个 SearchView,它在 ListView 中显示结果。我面临的问题是我有一个自定义键盘,而我的 Listview 与 keyboardView 重叠,所以我无法按下键盘上的某些键。我想要什么要实现的是我的Listview要显示在KeyboardView下。这是我的布局文件

<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);

有人可以指导我哪里出错或建议我应该如何进行。感谢您的帮助。

4

1 回答 1

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>
于 2013-05-30T04:27:38.683 回答