简体   繁体   English

如何禁用Android模拟器键盘弹出

[英]How can I disable the android emulator keyboard from popping up

In the following screenshot, I have an image that is followed by a scrollview. 在下面的屏幕截图中,我有一个图像, 后面是一个scrollview。 The scrollview contains a tablelayout and then some edittext fields, followed by a button scrollview包含一个tablelayout,然后是一些edittext字段,后跟一个按钮

在此输入图像描述

When I want to enter values into my fields, the keyboard pops up and it's blocking my view of the fields, like so: 当我想在我的字段中输入值时,键盘弹出并阻止我对字段的查看,如下所示:

在此输入图像描述

As you can see, it blocks my view of the edittext fields. 如您所见,它阻止了我对edittext字段的看法。 Is there an elegant fix for hiding the keyboard? 隐藏键盘是否有优雅的解决方案? If not, I will change my layout, however I'm not sure what to change. 如果没有,我会改变我的布局,但是我不知道该改变什么。 My layout looks like: 我的布局看起来像:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#CCCCCC"
    android:weightSum="1" android:id="@+id/llid">
    <TextView ... >
    </TextView> 
    <!-- Image inserted here as an ImageView from my code -->
    <ScrollView 
        android:id="@+id/svid"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginTop="3dp">
        <LinearLayout>
            <TableLayout ... >
                <TableRow>
                    <TextView ... />
                    <TextView ... />            
                </TableRow>
                <TableRow>
                    <TextView ... />
                    <TextView ... />            
                </TableRow> 
                <TableRow>
                    <TextView ... />
                    <TextView ... />            
                </TableRow>                         
            </TableLayout>
            <EditText>  
            ...
            </EditText>
            <EditText>  
            ...
            </EditText> 
            <EditText>  
            ...
            </EditText> 
            <Button>  
            ...
            </Button>                                           
        </LinearLayout>
    </ScrollView>   
</LinearLayout>

My first thought is go to the settings within the emulator: 我的第一个想法是去模拟器中的设置:

settings -> language and keyboard and uncheck "Android keyboard" and the other odd ones if they are checked too 设置 - >语言和键盘并取消选中“Android键盘”和其他奇怪的键盘,如果它们也被选中

Since the emulator is suppose to emulate what would be seen on the phone it makes sense that if you are trying to enter values into a text field the keyboard will pop up. 由于仿真器假设模拟手机上会看到的内容,因此如果您尝试在文本字段中输入值,则会弹出键盘。 I understand it can be irritating but, you should not try to disable it in your code, because that will disable it on the phone and then how will the user enter their inputs? 我知道这可能很烦人,但你不应该尝试在你的代码中禁用它,因为这会在手机上禁用它,然后用户将如何输入他们的输入?

Also, you can press the hardware back button to dismiss the keyboard when it pops up. 此外,您可以按硬件后退按钮以在弹出键盘时将其解除。

Programmatically you can set keyboard disabled by 以编程方式,您可以设置键盘禁用

public void removeKeyboard(EditText e, Context context){
    InputMethodManager keyB = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
    keyB.hideSoftInputFromWindow(e.getWindowToken(), 0);
}

where EditText e or some other view calling for text input 其中EditText或其他视图调用文本输入

UPDATE! UPDATE! If you set user input with SearchView i have found some short way to close down the keyboard by just 如果您使用SearchView设置用户输入,我发现了一些简短的方法来关闭键盘

nameButton.clearFocus();  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM