How to capture the “virtual keyboard show/hide” event in Android?

前端 未结 16 1372
暗喜
暗喜 2020-11-22 07:23

I would like to alter the layout based on whether the virtual keyboard is shown or not. I\'ve searched the API and various blogs but can\'t seem to find anything useful.

16条回答
  •  孤独总比滥情好
    2020-11-22 08:13

    I have solve the problem on single line textview back coding.

    package com.helpingdoc;
    
    import android.content.Context;
    import android.util.AttributeSet;
    import android.util.Log;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.widget.LinearLayout;
    
    public class MainSearchLayout extends LinearLayout {
        int hieght = 0;
        public MainSearchLayout(Context context, AttributeSet attributeSet) {
    
            super(context, attributeSet);
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            inflater.inflate(R.layout.main, this);
    
    
        }
    
        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            Log.d("Search Layout", "Handling Keyboard Window shown");
           if(getHeight()>hieght){
               hieght = getHeight();
           }
            final int proposedheight = MeasureSpec.getSize(heightMeasureSpec);
            final int actualHeight = getHeight();
            System.out.println("....hieght = "+ hieght);
            System.out.println("....actualhieght = "+ actualHeight);
            System.out.println("....proposedheight = "+ proposedheight);
            if (actualHeight > proposedheight){
                // Keyboard is shown
    
    
            } else if(actualHeight

提交回复
热议问题