setOnEditorActionListener 不适用于 Android Lollipop
setOnEditorActionListener is not working for Android Lollipop
我一直在尝试这个IME_ACTION
//Listening to the keyboard action
mSearchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == R.id.ime_search || actionId == EditorInfo.IME_ACTION_SEARCH) {
performSearch();
return true;
}
return false;
}
});
但似乎它在 Lollipop 设备上根本不起作用。
这是 XML 代码 - 我完全确定我做对了。
<org.mapunity.widget.FloatingEditText
android:id="@+id/fragment_search_edit_text"
android:hint="Enter a Text to Search"
android:layout_marginTop="@dimen/spacing_small"
android:layout_marginBottom="@dimen/spacing_small"
android:singleLine="true"
app:floating_edit_text_highlighted_color="@color/color_primary"
android:layout_marginLeft="@dimen/spacing_normal"
android:imeActionLabel="@string/action_search"
android:imeOptions="actionSearch"
android:imeActionId="@+id/ime_search"
android:inputType="text"
android:layout_marginRight="@dimen/spacing_normal"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<requestFocus></requestFocus>
</org.mapunity.widget.FloatingEditText>
请输入:
我知道有很多类似的问题,但我的问题是关于 Lollipop,即 Android 5.0+。
我遇到了和你一样的问题。所以,我用我拥有的设备做了一些测试。
结果表明 API > 19 的设备不响应 IME_ACTION
所以,解决方案就是删除代码中的 if
语句:
mSearchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
performSearch();
return true;
}
});
我一直在尝试这个IME_ACTION
//Listening to the keyboard action
mSearchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == R.id.ime_search || actionId == EditorInfo.IME_ACTION_SEARCH) {
performSearch();
return true;
}
return false;
}
});
但似乎它在 Lollipop 设备上根本不起作用。
这是 XML 代码 - 我完全确定我做对了。
<org.mapunity.widget.FloatingEditText
android:id="@+id/fragment_search_edit_text"
android:hint="Enter a Text to Search"
android:layout_marginTop="@dimen/spacing_small"
android:layout_marginBottom="@dimen/spacing_small"
android:singleLine="true"
app:floating_edit_text_highlighted_color="@color/color_primary"
android:layout_marginLeft="@dimen/spacing_normal"
android:imeActionLabel="@string/action_search"
android:imeOptions="actionSearch"
android:imeActionId="@+id/ime_search"
android:inputType="text"
android:layout_marginRight="@dimen/spacing_normal"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<requestFocus></requestFocus>
</org.mapunity.widget.FloatingEditText>
请输入:
我知道有很多类似的问题,但我的问题是关于 Lollipop,即 Android 5.0+。
我遇到了和你一样的问题。所以,我用我拥有的设备做了一些测试。
结果表明 API > 19 的设备不响应 IME_ACTION
所以,解决方案就是删除代码中的 if
语句:
mSearchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
performSearch();
return true;
}
});