我尝试了 setOnEditorActionListener ,它适用于我的三星(Android版本7.0)设备。但这对我的小米AndroidOne (Android版本9.0)设备不起作用。我该如何解决?
Java代码
mSearchText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if(actionId == EditorInfo.IME_ACTION_SEARCH
|| actionId == EditorInfo.IME_ACTION_DONE
|| event.getAction() == KeyEvent.ACTION_DOWN
|| event.getAction() == KeyEvent.KEYCODE_ENTER){
//execute our method for searching
geoLocate();
}
return false;
}
});
XML代码
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toRightOf="@+id/ic_magnify"
android:layout_centerVertical="true"
android:textSize="15sp"
android:textColor="#000"
android:id="@+id/input_search"
android:background="@null"
android:hint="Enter Address, City or Zip Code"
android:imeOptions="actionSearch"
/>
答案 0 :(得分:1)
它与 android:inputType =“ text”
答案 1 :(得分:0)
将属性 android:singleLine =“ true” 添加到对我有用的edittext中-如此处建议-> https://stackoverflow.com/a/53468182/5853160,您可以在此处找到有关此属性的更多信息-> {{3 }}
答案 2 :(得分:0)
<EditText
android:id="@+id/et_search_members"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="@dimen/dp_2"
android:layout_toRightOf="@+id/iv_search_icon"
android:background="@android:color/transparent"
android:hint="搜索分组/姓名"
android:imeOptions="actionSearch"
android:inputType="text"
android:singleLine="true"></EditText>
et_search_members.setOnEditorActionListener(OnEditorActionListener { v, actionId, event ->
if (actionId== EditorInfo.IME_ACTION_SEARCH) {
sendSearchData()
}
false
})