gpt4 book ai didi

android - imeOptions actionDone with Android 2.3

转载 作者:行者123 更新时间:2023-11-29 22:19:51 25 4
gpt4 key购买 nike

我有几个 EditText,我已将 imeOptions 设置为 actionDone。当我使用 Android 2.1 或 Android 2.2 在模拟器中运行我的应用程序时,虚拟键盘上的回车键变为“完成”。

但是,(而且我还没有在模拟器中测试过),当我在运行 Android 2.3(直接 2.3,Nexus S)的手机上运行我的应用程序时,虚拟键盘上的回车键仍然是返回按钮并按下它会在 EditText 中输入一个换行符。

如何让虚拟键盘上的返回键在 Android 2.3 中说出和表现得像“完成”?

最佳答案

我已经按照下面的方式实现了,它对我来说效果很好。尝试一下它可能会对您有所帮助。

  EditText m_etDone = (EditText) findViewById(R.id.am_etDone);  
EditText m_etSearch = (EditText) findViewById(R.id.am_etSearch);
m_etDone.setOnEditorActionListener(new DoneOnEditorActionListener());
m_etSearch.setOnEditorActionListener(new DoneOnEditorActionListener());
class DoneOnEditorActionListener implements OnEditorActionListener {
@Override
public boolean onEditorAction(TextView p_v, int p_actionId, KeyEvent p_event) {
if (p_actionId == EditorInfo.IME_ACTION_DONE)
{
InputMethodManager m_imm = (InputMethodManager)p_v.getContext() .getSystemService(Context.INPUT_METHOD_SERVICE);
m_imm.hideSoftInputFromWindow(p_v.getWindowToken(), 0);
return true;
}
else if(p_actionId == EditorInfo.IME_ACTION_SEARCH)
{
Toast.makeText(getApplicationContext(),"Search Text",Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
}

布局文件:

<EditText 
android:id="@+id/am_etDone"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Enter some text"
android:imeOptions="actionNext"
android:singleLine="true"
android:imeActionLabel="Done"/>
<EditText
android:id="@+id/am_etSearch"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Enter search text"
android:imeOptions="actionSearch"
android:singleLine="true"
android:layout_below="@+id/am_etDone"
android:imeActionLabel="Search"/>

关于android - imeOptions actionDone with Android 2.3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7534631/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com