gpt4 book ai didi

android - 软键盘上的搜索图标

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:35:30 27 4
gpt4 key购买 nike

我有一个用于 MenuItems 的 searchIcon 的 ActionLayout。这个 ActionLayout 有一个 AutoCompleteTextView,它有 imeOption = "actionSearch"

但是当我点击 menuItems 和 ActionLayout 出现时,软键盘弹出,但它仍然有换行键而不是 searchIcon。

Activity 代码:

private AutoCompleteTextView mEtSearchbar;
private MenuItem mSearchbar;

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {

case R.id.searchIcon:

mEtSearchbar.clearFocus();
(new Handler()).postDelayed(new Runnable() {
public void run() {
mEtSearchbar.dispatchTouchEvent(MotionEvent.obtain(
SystemClock.uptimeMillis(),
SystemClock.uptimeMillis(),
MotionEvent.ACTION_DOWN, 0, 0, 0));
mEtSearchbar.dispatchTouchEvent(MotionEvent.obtain(
SystemClock.uptimeMillis(),
SystemClock.uptimeMillis(), MotionEvent.ACTION_UP,
0, 0, 0));
}
}, 100);
return true;
default:
return super.onOptionsItemSelected(item);
}
}

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
// TODO Auto-generated method stub
inflater.inflate(R.menu.m_menu, menu);


mSearchbar = (MenuItem) menu.findItem(R.id.searchIcon);
View actionview = mSearchbar.getActionView();
mEtSearchbar = ((AutoCompleteTextView) actionview
.findViewById(R.id.search_editText));
final ImageView searchImage = ((ImageView) actionview
.findViewById(R.id.search_image));
searchImage.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View arg0) {

String s = mEtSearchbar.getText().toString();

Intent intent = new Intent(getSherlockActivity(),
SearchActivity.class);
intent.putExtra("search_string", s);
startActivity(intent);
}
});

mEtSearchbar
.setOnEditorActionListener(new TextView.OnEditorActionListener() {

@Override
public boolean onEditorAction(TextView v, int actionId,
KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {

searchImage.performClick();
return true;
}
return false;
}
});

super.onCreateOptionsMenu(menu, inflater);
}

*菜单布局*t

m_menu.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android" >

<item
android:id="@+id/searchIcon"
android:actionLayout="@layout/search_icon_actionview"
android:icon="@drawable/search_icon"
android:showAsAction="ifRoom|collapseActionView"
android:title="Search"/>
<item
android:id="@+id/notificationIcon"
android:icon="@drawable/notification_icon"
android:orderInCategory="0"
android:showAsAction="ifRoom|collapseActionView"
android:title="Notifications"/>

</menu>

search_icon_actionview.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<ImageView
android:id="@+id/search_image"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:clickable="true"
android:contentDescription="Search icon"
android:src="@drawable/search_icon" />

<AutoCompleteTextView
android:id="@+id/search_editText"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_toLeftOf="@id/search_image"
android:hint="Search"
android:imeOptions="actionSearch" />

</RelativeLayout>

如何在软键盘上有一个 searchIcon 或至少一个 done 按钮,点击时必须执行 searchIcon i 的点击有 ActionLayout

谢谢

最佳答案

我要补充

android:singleLine="true" 

还有

关于android - 软键盘上的搜索图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13985146/

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