Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/212.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 Activity_Keyboard - Fatal编程技术网

Android 如何在活动开始时隐藏键盘

Android 如何在活动开始时隐藏键盘,android,android-activity,keyboard,Android,Android Activity,Keyboard,我有一个有很多编辑文本的活动。每当我加载该活动时,键盘就会出现并占据屏幕的一半,这使得该活动看起来很糟糕。所以,当我加载那个活动时,有没有办法隐藏键盘呢 您可以使用intputmethodmangare进行此操作。。。使用以下代码 getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); InputMethodManager imm = (InputMethodManager)getSys

我有一个有很多编辑文本的活动。每当我加载该活动时,键盘就会出现并占据屏幕的一半,这使得该活动看起来很糟糕。所以,当我加载那个活动时,有没有办法隐藏键盘呢

您可以使用intputmethodmangare进行此操作。。。使用以下代码

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
InputMethodManager imm = (InputMethodManager)getSystemService(
      Context.INPUT_METHOD_SERVICE);

imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);
在onCreate()中,请使用此

this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

在RootLayout中的活动XML文件中添加这两行,即相对或线性(无论您采取了什么):

在活动清单文件中添加此行

 android:windowSoftInputMode="stateHidden"

在AndroidManifest.xml中添加属性android:windowSoftInputMode

<activity android:name="your.package.ActivityName"
      android:windowSoftInputMode="stateHidden"  />

将此代码放在
混凝土功能上:

new Handler().postDelayed(new Runnable()){
@凌驾
公开募捐{
InputMethodManager imm=(InputMethodManager)getSystemService(Context.INPUT\u方法\u服务);
imm.hideSoftInputFromWindow(view.getWindowToken(),0);
view.clearFocus();
}}, 50);

其中
view
是您的编辑文本


之所以可以运行,是因为代码可能在呈现
editText
之前执行。

我创建了一个方法,在onCreate事件中调用所有必需的活动类。在所有情况下都对我有效

public class ClassLib {
        public static void hideKeyboard(Activity activity) {
        //Hide keyboard
        activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    }
}

@阿弥陀佛,苏迪普塔佛罗,阿弥陀佛比斯瓦斯。谢谢,快乐编码。!可能重复的
public class ClassLib {
        public static void hideKeyboard(Activity activity) {
        //Hide keyboard
        activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    }
}