Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/193.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android软键盘在2.2/2.3中不会显示,但在3.0+;_Android_Android Edittext_Actionbarsherlock_Android Softkeyboard - Fatal编程技术网

Android软键盘在2.2/2.3中不会显示,但在3.0+;

Android软键盘在2.2/2.3中不会显示,但在3.0+;,android,android-edittext,actionbarsherlock,android-softkeyboard,Android,Android Edittext,Actionbarsherlock,Android Softkeyboard,我的应用程序在安卓2.2及更高版本上运行。在其中,我使用允许对3.0之前的设备使用操作栏。我在操作栏中使用了EditText来允许用户输入搜索文本 使用仿真器,使用Android 4.0和4.1(我没有尝试3.x,因为它不是平板电脑应用程序),当选择EditText时,软键盘会根据需要弹出。但使用安卓2.2或2.3.3时情况并非如此,它只是无法显示 EditText的代码很简单: item.setActionView(R.layout.collapsible_edittext); etInput

我的应用程序在安卓2.2及更高版本上运行。在其中,我使用允许对3.0之前的设备使用操作栏。我在操作栏中使用了EditText来允许用户输入搜索文本

使用仿真器,使用Android 4.0和4.1(我没有尝试3.x,因为它不是平板电脑应用程序),当选择EditText时,软键盘会根据需要弹出。但使用安卓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"/>
我想弄清楚这是ActionbarSherlock的问题还是Android的一个更普遍的问题。我浏览了很多关于在活动中强制使用软键盘显示的文章,但还没有找到解决方案


谢谢

我也有同样的问题。。。在我对HTC Nexus One进行测试之前,一切正常。最后,我向连接到AcionBarSherlock菜单项的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);
 }  
}
item.setOnActionExpandListener(新的OnActionExpandListener(){
@凌驾
公共布尔值onMenuItemActionExpand(MenuItem项){
//post延迟,以便有时间显示edittext
mHandler.postDelayed(新的Runnable(){
@凌驾
公开募捐{
mSearchText.clearFocus();
showKeyboard();
mSearchText.requestFocus();
}
}, 400);
返回true;
}
@凌驾
公共布尔值onMenuItemActionCollapse(MenuItem项){
隐藏板();
返回true;
}
});
私有void showKeyboard(){
if(android.os.Build.VERSION.SDK_INT<11){
mInputManager.toggleSoftInput(InputMethodManager.SHOW\u强制,InputMethodManager.HIDE\u隐式);
}否则{
mInputManager.showSoftInput(mSearchText,InputMethodManager.SHOW_隐式);
}
}
私有void隐藏板(){
if(android.os.Build.VERSION.SDK_INT<11){
mInputManager.hideSoftInputFromWindow(getActivity().getWindow().getCurrentFocus().getWindowToken(),0);
}否则{
mInputManager.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(),InputMethodManager.HIDE\u不总是);
}  
}

对于在C sharp中使用Mono droid的人员,以下是代码:

         new Thread(new ThreadStart(() =>
         {
             while (DateTime.Now < _dt)
                 Thread.Sleep(10);
             RunOnUiThread(showKeyboard);
         }
           )).Start();



     protected void showKeyboard()
     {
         int osSDK = (int)Android.OS.Build.VERSION.SdkInt;

         if (osSDK < 11)
         {
             this.mm().ToggleSoftInput(ShowFlags.Forced, HideSoftInputFlags.ImplicitOnly);
         }
         else
         { 
            EditText editTextView = FindViewById<EditText>(Resource.Id.EditTextSubCellAddVenue);
            this.mm().ShowSoftInput(editTextView, ShowFlags.Implicit);
         }
     }

     protected void hideKeyboard()
     {
         int osSDK = (int)Android.OS.Build.VERSION.SdkInt;

         if (osSDK < 11)
         {
             this.mm().HideSoftInputFromWindow(this.Window.CurrentFocus.WindowToken, 0);
         }
         else
         {
             this.mm().HideSoftInputFromWindow(this.CurrentFocus.WindowToken, HideSoftInputFlags.NotAlways);
         }
     }

     protected InputMethodManager mm()
     {
         if (imm == null)
         {
             EditText editTextView = FindViewById<EditText>(Resource.Id.EditTextSubCellAddVenue);

             imm = (InputMethodManager)this.GetSystemService(Android.Content.Context.InputMethodService);
         }

         return imm;
     }
新线程(新线程开始(()=>
{
while(DateTime.Now<\u dt)
睡眠(10);
RunOnUiThread(显示键盘);
}
)).Start();
受保护的void showKeyboard()
{
int osSDK=(int)Android.OS.Build.VERSION.SdkInt;
如果(osSDK<11)
{
this.mm().ToggleSoftInput(ShowFlags.Forced,HideSoftInputFlags.ImplicitOnly);
}
其他的
{ 
EditText editTextView=FindViewById(Resource.Id.EditTextSubcelladdVince);
this.mm().ShowSoftInput(editTextView,ShowFlags.Implicit);
}
}
受保护的无效隐藏板()
{
int osSDK=(int)Android.OS.Build.VERSION.SdkInt;
如果(osSDK<11)
{
this.mm().HideSoftInputFromWindow(this.Window.CurrentFocus.WindowToken,0);
}
其他的
{
this.mm().HideSoftInputFromWindow(this.CurrentFocus.WindowToken,HideSoftInputFlags.NotAlways);
}
}
受保护的InputMethodManager mm()
{
if(imm==null)
{
EditText editTextView=FindViewById(Resource.Id.EditTextSubcelladdVince);
imm=(InputMethodManager)this.GetSystemService(Android.Content.Context.InputMethodService);
}
返回imm;
}

使用
clearFocus()
per[this post][1]解决了我的问题。[1] :你把clearFocus()调用放在哪里了?Clear focus!这就是我需要做的!!此外,我将请求的焦点放在视图处理程序上,这样我就不必猜测延迟多长时间,这就是我在这里的建议。再次感谢!!
         new Thread(new ThreadStart(() =>
         {
             while (DateTime.Now < _dt)
                 Thread.Sleep(10);
             RunOnUiThread(showKeyboard);
         }
           )).Start();



     protected void showKeyboard()
     {
         int osSDK = (int)Android.OS.Build.VERSION.SdkInt;

         if (osSDK < 11)
         {
             this.mm().ToggleSoftInput(ShowFlags.Forced, HideSoftInputFlags.ImplicitOnly);
         }
         else
         { 
            EditText editTextView = FindViewById<EditText>(Resource.Id.EditTextSubCellAddVenue);
            this.mm().ShowSoftInput(editTextView, ShowFlags.Implicit);
         }
     }

     protected void hideKeyboard()
     {
         int osSDK = (int)Android.OS.Build.VERSION.SdkInt;

         if (osSDK < 11)
         {
             this.mm().HideSoftInputFromWindow(this.Window.CurrentFocus.WindowToken, 0);
         }
         else
         {
             this.mm().HideSoftInputFromWindow(this.CurrentFocus.WindowToken, HideSoftInputFlags.NotAlways);
         }
     }

     protected InputMethodManager mm()
     {
         if (imm == null)
         {
             EditText editTextView = FindViewById<EditText>(Resource.Id.EditTextSubCellAddVenue);

             imm = (InputMethodManager)this.GetSystemService(Android.Content.Context.InputMethodService);
         }

         return imm;
     }