
使用模拟器,使用AndroID 4.0和4.1(我没有尝试3.x,因为它不是平板电脑应用程序),当选择EditText时,软键盘会根据需要d出.但不是这样使用AndroID 2.2或2.3.3,它只是不显示.
EditText的代码很简单:
item.setActionVIEw(R.layout.collapsible_edittext);etinput = (EditText) item.getActionVIEw().findVIEwByID(R.ID.etinput); etinput.requestFocus();
布局:
<?xml version="1.0" enCoding="utf-8"?><EditText xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:ID="@+ID/etinput" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" androID:hint="@string/search_hint" androID:lines="1" androID:maxlines="1" androID:inputType="textFilter|textNoSuggestions" androID:imeOptions="actionSend"/>
现在我尝试在etinput.requestFocus();之后立即使用此代码段专门显示软键盘,但它没有区别:
inputMethodManager imm = (inputMethodManager)getSystemService(Context.input_METHOD_SERVICE);imm.showSoftinput(etinput,inputMethodManager.SHOW_IMPliCIT);
我试图弄清楚这是ActionbarSherlock的问题还是更普遍的AndroID问题.我在一篇活动中搜索了许多关于强制软键盘显示的文章,但还没有找到解决方案.
谢谢
解决方法 我有同样的问题……一切正常,直到我在HTC Nexus One上测试.我最终将以下代码添加到附加到AciontbarSherlock menuItem的onActionExpandListener.item.setonActionExpandListener(new OnActionExpandListener() { @OverrIDe public boolean onMenuItemActionExpand(MenuItem item) { // post delayed to allow time for edittext to become visible mHandler.postDelayed(new Runnable() { @OverrIDe public voID run() { mSearchText.clearFocus(); showKeyboard(); mSearchText.requestFocus(); } },400); return true; } @OverrIDe public boolean onMenuItemActionCollapse(MenuItem item) { hIDeKeyboard(); return true; }});private voID showKeyboard() { if (androID.os.Build.VERSION.SDK_INT < 11) { minputManager.toggleSoftinput(inputMethodManager.SHOW_FORCED,inputMethodManager.HIDE_IMPliCIT_ONLY); } else { minputManager.showSoftinput(mSearchText,inputMethodManager.SHOW_IMPliCIT); }}private voID hIDeKeyboard() { if (androID.os.Build.VERSION.SDK_INT < 11) { minputManager.hIDeSoftinputFromWindow(getActivity().getwindow().getCurrentFocus().getwindowToken(),0); } else { minputManager.hIDeSoftinputFromWindow(getActivity().getCurrentFocus().getwindowToken(),inputMethodManager.HIDE_NOT_ALWAYS); } } 总结 以上是内存溢出为你收集整理的Android软键盘不会在2.2/2.3中显示,但会在3.0中显示全部内容,希望文章能够帮你解决Android软键盘不会在2.2/2.3中显示,但会在3.0中显示所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)