简体   繁体   中英

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. The scrollview contains a tablelayout and then some edittext fields, followed by a button

在此输入图像描述

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. 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

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

UPDATE! If you set user input with SearchView i have found some short way to close down the keyboard by just

nameButton.clearFocus();  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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