Android 4.0.3切换使用软键盘上的搜索按钮进入按钮

时间:2012-08-23 10:08:46

标签: android

我正在尝试使用它:在EditText的XML中,我有:

    android:imeActionLabel="Search"
    android:imeOptions="actionSearch"

但它不起作用。在代码中

    search.setImeOptions(EditorInfo.IME_ACTION_SEARCH);

也不起作用。有线索吗?

1 个答案:

答案 0 :(得分:1)

试试这个

你的xml文件中的

<EditText
            android:id="@+id/rechercheTextView"
            android:layout_width="174dp"
            android:layout_height="wrap_content"
            android:background="@android:color/transparent"
            android:imeOptions="actionSearch"
            android:inputType="text"
             />

在你的活动中

EditText rechTxt = (EditText) findViewById(R.id.rechercheTextView);
rechTxt.setOnEditorActionListener(new OnEditorActionListener() {

    public boolean onEditorAction(TextView v, int actionId,
                        KeyEvent event) {
    if (actionId == EditorInfo.IME_ACTION_SEARCH) {

        Toast.makeText(getApplicationContext(),"search",Toast.LENGTH_LONG).show();
        return true;
                    }
                    return false;
                }
            });