Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/228.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 软键盘有问题吗_Android_Android Widget_Android Manifest_Android Softkeyboard - Fatal编程技术网

Android 软键盘有问题吗

Android 软键盘有问题吗,android,android-widget,android-manifest,android-softkeyboard,Android,Android Widget,Android Manifest,Android Softkeyboard,大家好,我是Android新手,在我的项目中遇到了一个非常愚蠢的问题,我有一个EditText,它定义在列表视图的标题视图中,每当用户触摸EditText软键盘时,就会显示出来。我有一个叫做clear button的东西,它在清除2.3设备中未显示的软键盘后清除编辑文本。每当我按下lock/power button锁定设备并解锁时,软键盘就会显示 <activity android:name=".pl.Mobile.AddJobNew" android:co

大家好,我是Android新手,在我的项目中遇到了一个非常愚蠢的问题,我有一个EditText,它定义在列表视图的标题视图中,每当用户触摸EditText软键盘时,就会显示出来。我有一个叫做clear button的东西,它在清除2.3设备中未显示的软键盘后清除编辑文本。每当我按下lock/power button锁定设备并解锁时,软键盘就会显示

<activity
        android:name=".pl.Mobile.AddJobNew"
        android:configChanges="orientation|keyboardHidden"
        android:screenOrientation="landscape"
        android:windowSoftInputMode="stateVisible|adjustResize|adjustPan"
         >

以下是我在Android for Android中的活动声明:WindowsOfInputMode:“adjustResize”选项对Android 2.3设备非常有效,但在软键盘与编辑文本重叠的4.0设备中失败。选项“adjustPan”在4.0设备中工作正常,但在2.3设备中失败

请帮我摆脱这个问题


提前感谢

在活动中尝试以下编辑文本:

int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if (currentapiVersion >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH){
// Do something for 4.0 and above versions
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
} 
else{
// do something for phones running an SDK before 4.0
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
}
也去掉,

android:windowSoftInputMode="stateVisible|adjustResize|adjustPan"
从清单文件中的活动


我的AndroidManifest.xml文件中有下面一行,它工作得很好。请尝试此代码。不要放任何额外的代码。如果你没有成功,请告诉我。我愿意帮助你

<activity android:name=".pl.Mobile.AddJobNew" android:screenOrientation="portrait" android:configChanges="keyboard|orientation" android:windowSoftInputMode="adjustPan"/>


请尝试使用上述活动代码。

我认为问题在于,当您单击“清除”按钮时,编辑文本会失去焦点,因此键盘会隐藏自己

我会尝试两件事来解决它

  • 清理文本后,请执行以下操作:

    yourEditTextField.requestFocus()

  • 手动控制键盘可见性:

    公用键盘(){ 视图=getWindow().getCurrentFocus(); 如果(视图==null) 返回

    InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.showSoftInput(view, InputMethodManager.SHOW_FORCED);
    
    IBinder binder = view.getWindowToken();
    if (binder == null)
        return;
    
     // prevent a bug in some keyboards that makes the text hang on the screen
    if (view instanceof EditText) 
        ((EditText)view).setText(((EditText)view).getText().toString());
    
    
    InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(binder, InputMethodManager.HIDE_NOT_ALWAYS);
    
    }

    公共无效隐藏板(){ 视图=getWindow().getCurrentFocus(); 如果(视图==null) 返回

    InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.showSoftInput(view, InputMethodManager.SHOW_FORCED);
    
    IBinder binder = view.getWindowToken();
    if (binder == null)
        return;
    
     // prevent a bug in some keyboards that makes the text hang on the screen
    if (view instanceof EditText) 
        ((EditText)view).setText(((EditText)view).getText().toString());
    
    
    InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(binder, InputMethodManager.HIDE_NOT_ALWAYS);
    
    }


  • 试试那样的

        editext1.setOnTouchListener(new OnTouchListener()
                {
    
                    public boolean onTouch(View v, MotionEvent event)
                    {
                        if (v instanceof EditText)
                        {
                            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                            imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
                            v.requestFocusFromTouch();
                            return true;
                        }
                        return false;
                    }
                });
    
    如果它不适合您,请尝试添加

            editext1.setOnFocusChangeListener(new OnFocusChangeListener()
            {
    
                public void onFocusChange(View v, boolean hasFocus)
                {
                    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
                }
            });
    

    从布局中删除请求焦点也很好。并且可以在活动清单中设置此android:windowSoftInputMode=“stateHidden | stateAllwayshidden”

    从编辑文本中删除请求焦点(如果编辑文本已删除)it@SoftwareSainath-如果我的解决方案对您有效,请接受。