Android: Detect softkeyboard open

后端 未结 8 2127
栀梦
栀梦 2020-11-29 07:31

When the soft keyboard opens I want a scroll view to scroll down to the bottom.

For this I can use: fullScroll(View.FOCUS_DOWN);

But how do I fire that comma

8条回答
  •  萌比男神i
    2020-11-29 07:54

    watching the date , possibly you have a solution for your question, otherwise:

    Here is the same response i made to another question related : Is there a way to tell if the soft-keyboard is shown?

    but i copy full response here to avoid dead links:

    Please check Configuration Changes for your Activity

    This for your AndroidManifest.xml

    and this for your Activity class http://developer.android.com/reference/android/app/Activity.html#onConfigurationChanged(android.content.res.Configuration)

    You will need to @Override the public method onConfigurationChanged(android.content.res.Configuration) of your Activity to be able to handle, for example, this values:
    hardKeyboardHidden,
    keyboard,
    keyboardHidden

    For all possible values check http://developer.android.com/reference/android/content/res/Configuration.html

    You will see there something like this:

    HARDKEYBOARDHIDDEN_NO   
    HARDKEYBOARDHIDDEN_UNDEFINED    
    HARDKEYBOARDHIDDEN_YES  
    KEYBOARDHIDDEN_NO   
    KEYBOARDHIDDEN_UNDEFINED    
    KEYBOARDHIDDEN_YES  
    KEYBOARD_12KEY  
    KEYBOARD_NOKEYS 
    KEYBOARD_QWERTY 
    KEYBOARD_UNDEFINED
    

    Also there you will be able to read something like this:

    public int  hardKeyboardHidden  A flag indicating whether the hard keyboard has been      hidden.
    public int  keyboard    The kind of keyboard attached to the device.
    public int  keyboardHidden  A flag indicating whether any keyboard is available.
    

    UPDATE:

    Here is a specific sample of what i´m talking about:

    http://developer.android.com/guide/topics/resources/runtime-changes.html

        
    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
    
        // Checks the orientation of the screen
        if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
            Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
        } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
            Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
        }
        // Checks whether a hardware keyboard is available
        if (newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) {
            Toast.makeText(this, "keyboard visible", Toast.LENGTH_SHORT).show();
        } else if (newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES) {
            Toast.makeText(this, "keyboard hidden", Toast.LENGTH_SHORT).show();
        }
    }
    

    I hope this help you

提交回复
热议问题