但是当我单击menuItems并显示ActionLayout时,d出软键盘,但它仍然有换行键而不是searchIcon.
活动代码:
private autoCompleteTextVIEw mEtSearchbar;private MenuItem mSearchbar;@OverrIDepublic 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)); mEtSearchbar.dispatchtouchEvent(MotionEvent.obtain( SystemClock.uptimeMillis(),MotionEvent.ACTION_UP,0)); } },100); return true; default: return super.onoptionsItemSelected(item); }}@OverrIDepublic 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);}
* menu layou * 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或至少一个完成按钮,点击它必须执行我在ActionLayout中的searcIcon点击
谢谢
解决方法 我必须补充一下androID:singleline="true"
也
总结以上是内存溢出为你收集整理的android – 软键盘上的搜索图标全部内容,希望文章能够帮你解决android – 软键盘上的搜索图标所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)