2012-08-23 103 views
1

我试图得到这个工作与搜索键按钮:在我的XML在我的EditText有:的Android 4.0.3切换输入软键盘

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

但它不工作。代码

search.setImeOptions(EditorInfo.IME_ACTION_SEARCH); 

也不管用。任何线索?

+0

它的工作原理是在你按下回车键时,正确的行动,但我认为谷歌决定不切换按钮外观/键盘布局。 – zapl

回答

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