【问题标题】:Android: Search button instead of Enter for EditTextAndroid:搜索按钮而不是 EditText 的 Enter
【发布时间】:2011-12-20 08:46:07
【问题描述】:

我有以下编辑文本:

    <EditText
         android:paddingTop="10dip" android:paddingBottom="10dip"
android:paddingRight="10dip" android:paddingLeft="10dip"
        android:id="@+id/myBookSearchEditTextId"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:background="@color/white"
        android:saveEnabled="true"
        android:scrollHorizontally="true"
        android:selectAllOnFocus="true"
        android:imeOptions="actionSearch"
        android:text="Search"
        android:textColor="@color/black" >

        <requestFocus />
    </EditText>

为什么我仍然在键盘上看到 Enter 键而不是 Search 键?

我发现了一些东西 - 似乎在使用软键盘时它有一个问题...... 正如在网上找到的 - 可能需要在编辑文本上的 OnClick 中获取 InputmethodManager:

...Onclick(...)
{
    InputmethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(view.getWindowToken(), 0 );
}

【问题讨论】:

  • 您是在设备上测试还是在模拟器上测试?这里的 requestFocus 是什么?
  • 您使用的是哪个 api 级别?
  • 在设备上测试。在设备上进行测试时——项目设置到哪个 API 级别是否重要?它设置为 Min API 级别 8。
  • 顺便说一句 - 在设备上 - 如果我在 Android Market 中输入搜索,我会看到搜索按钮应该是。

标签: android search android-edittext


【解决方案1】:

试试这个.. editTx.setImeActionLabel("Search",EditorInfo.IME_ACTION_SEARCH);而不是在布局 xml 中。

【讨论】:

    【解决方案2】:

    在我添加 inputType 之前,我的搜索图标没有显示。

    这两个都是必需的:

    android:imeOptions="actionSearch"

    和

    android:inputType="text"

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-07
      • 2020-07-22
      • 2015-11-24
      • 2016-07-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多