- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用 Android Studio 抽屉导航预设生成了此 Activity ,因此 EditText 位于 fragment 内。我想做的是在按下键盘上的“发送”按钮后创建一个通知。当我单击按钮时没有任何反应,onEditorAction 没有被调用。有谁知道如何解决这个问题吗?
inflatedView = getLayoutInflater().inflate(R.layout.fragment_main, null);
EditText noteText = (EditText) inflatedView.findViewById(R.id.write_note);
noteText.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
boolean handled = false;
if (actionId == EditorInfo.IME_ACTION_SEND) {
createNotification();
handled = true;
}
return handled;
}
});
fragment_main.xml
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/write_note"
android:background="@drawable/edit_text_outline"
android:layout_below="@+id/textView"
android:textSize="22sp"
android:textColor="#ffffffff"
android:textColorHint="#c8ffffff"
android:layout_marginTop="42dp"
android:inputType="textAutoCorrect|textCapSentences"
android:imeOptions="actionSend"
android:singleLine="true"
android:hint="@string/edit_text_hint" />
最佳答案
这样做,请在edittext中设置“android:imeOptions=”actionSend”。
noteText.setOnEditorActionListener(new TextView.OnEditorActionListener()
{
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
{
boolean handled = false;
if (actionId == EditorInfo.IME_ACTION_SEND)
{
createNotification();
handled = true;
}
return handled;
}
});
将其放入 xml 中,
<EditText
android:id="@+id/test"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionSend"
android:singleLine="true" />
这对我有用。您可以使用如下代码进行计算后隐藏软键盘:
InputMethodManager imm= (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
关于java - onEditorAction 未在 fragment 中调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29313630/
大家好,第一次在 Stack 上发帖,请耐心等待。 我正在尝试在用户按下 EditText 中的回车键后关闭 IME。 我尝试在 layout.xml 中使用 android:imeOptions="
我正在尝试捕捉从屏幕上移除键盘的事件,并且我正在使用 OnEditorActionListener 类。但是,它的 onEditorAction 方法永远不会被调用。 这是我的 XML EditTex
我使用 Android Studio 抽屉导航预设生成了此 Activity ,因此 EditText 位于 fragment 内。我想做的是在按下键盘上的“发送”按钮后创建一个通知。当我单击按钮时没
TextView 的onEditorAction 方法的文档说 Return true if you have consumed the action, else false. 我在网上看到的大多数示
我有一个 EditText View : 我想在用户插入输入时禁用“enter”键。 相反,我希望键盘有一个“完成”键来关闭软键盘。 添加 android:imeOptions="actio
我的 fragment 中有一个 EditText,当我执行输入或任何类似输入的操作时,我想做一些事情。但是我在 KeyEvent 或 actionId 的 onEditorAction id 上遇到
我对最新的 Jelly Bean 模拟器的行为有疑问。我的应用中有几个 EditTexts。 OnEditorActionListener 在用户按下键盘上的 ENTER 键时提供特殊处理。这在 IC
我正在尝试将 ButterKnife 的接口(interface) OnEditorAction 用于 EditText 的“ENTER”事件 @OnEditorAction(R.id.et_good
喜欢下面的代码 我想从 XML 调用 editorAction,是否可以通过 xml 执行它? 最佳答案 1.创建界面 interface CustomOnEditorActionLi
情况:我有一个包含 EditText 的 View 列表。我希望用户能够修改文本,并且只在他按下键盘上的完成按钮时才将他的新文本发送到 View 模型。我的编辑文本已绑定(bind)有后续 我在互联
我有一个编辑文本,它在我的应用程序中用作搜索框。在我的 Nexus 7 上的 Jelly Bean 中,当我在我正在收听的文本框中输入一些内容并点击输入 KeyEvent = null 和 Actio
我是一名优秀的程序员,十分优秀!