应用启动时会自动显示键盘吗?

时间:2019-07-06 18:34:37

标签: java android android-edittext keyboard

在MainActivity中,我添加了一个EditText。 当用户打开应用程序时,键盘会自动显示以允许用户键入文本,但是我的应用程序在onCreate()中显示广告,因此我想禁用该自动事件,可以吗?

3 个答案:

答案 0 :(得分:0)

使用以下功能显示/隐藏键盘:

隐藏软键盘

public void hideSoftKeyboard() {
    if(getCurrentFocus()!=null) {
        InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
        inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
    }
}

显示软键盘

public void showSoftKeyboard(View view) {
    InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
    view.requestFocus();
    inputMethodManager.showSoftInput(view, 0);
}

或者您可以设置windowSoftInputMode:stateHidden

    <activity
    ... 
    android:windowSoftInputMode="stateHidden">

答案 1 :(得分:0)

在AndroidManifest.xml中,您可以使用以下设置:

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

您也可以尝试:

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

您可以在此link上找到更多详细信息。

答案 2 :(得分:0)

是有可能的,您有两种选择可以实现。

选项1: 在布局中添加以下代码-xml文件

Sub MisRec()
    Dim ws As Worksheet, f As Range
    For Each ws In Worksheets
            Set f = ws.Cells.Find(What:="abc", After:=ActiveCell, LookIn:=xlFormulas, _
                    LookAt:= xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
                    MatchCase:=False, SearchFormat:=False)
            If Not f Is Nothing then
                ws.Range(f.Offset(-2, 0), ws.Range("A2")).EntireRow.Delete
            End If
    Next ws
End Sub

选项2:

在清单文件中添加以下代码

android:focusable="true"
android:focusableInTouchMode="true"

只需将此行添加到您的android清单文件即可禁用显示键盘。 (您的活动)