アンドロイドモニターの入力方法がポップアップして非表示

最初の方法:

   この方法は、仮想ボタンを備えた電話と互換性があります。

rlAll.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
    @Override
    public void onGlobalLayout() {
        if (rlAll.getHeight() == 0) {
            return;
        }
        if(isCome){
            //在布局完成后再执行判断.
            //获取当前界面高度跟开始的布局高度比较(有虚拟键的手机要判断一下(navigationBarHeight虚拟按键的高度,因为当用户把虚拟按键弹出会触发布局会判断小于而混乱.))
            if((mTypewrit -scrollView.getHeight())> navigationBarHeight){
                Log.e("aaa", "onGlobalLayout: "+"输入法弹出了");
                btnNext.setVisibility(View.GONE);
            }else{
                Log.e("aaa", "onGlobalLayout: "+"输入法隐藏了");
                btnNext.setVisibility(View.VISIBLE);
            }
        }
        if (!isCome) {
            //这里获取布局完成后界面的高度,(注意值能控制方法执行一次,不然Typewrit会重复赋值,无法判断)
            isCome = true;
            mTypewrit =rlAll.getHeight();
        }
    }
});

もちろん、仮想ボタンの取得もあります。

public class FictitiousUtils {
    //获取虚拟按键的高度
    public static int getNavigationBarHeight(Context context) {
        int result = 0;
        if (hasfictitious(context)) {
            Resources res = context.getResources();
            int resourceId = res.getIdentifier("navigation_bar_height", "dimen", "android");
            if (resourceId > 0) {
                result = res.getDimensionPixelSize(resourceId);
            }
        }
        return result;
    }

    /**
     * 检查是否存在虚拟按键栏
     *
     * @param context
     * @return
     */
    @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
    public static boolean hasfictitious(Context context) {
        Resources res = context.getResources();
        int resourceId = res.getIdentifier("config_showNavigationBar", "bool", "android");
        if (resourceId != 0) {
            boolean hasNav = res.getBoolean(resourceId);
            // check override flag
            String sNavBarOverride = getNavBarOverride();
            if ("1".equals(sNavBarOverride)) {
                hasNav = false;
            } else if ("0".equals(sNavBarOverride)) {
                hasNav = true;
            }
            return hasNav;
        } else { // fallback
            return !ViewConfiguration.get(context).hasPermanentMenuKey();
        }
    }

    /**
     * 判断虚拟按键栏是否重写
     *
     * @return
     */
    private static String getNavBarOverride() {
        String sNavBarOverride = null;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            try {
                Class c = Class.forName("android.os.SystemProperties");
                Method m = c.getDeclaredMethod("get", String.class);
                m.setAccessible(true);
                sNavBarOverride = (String) m.invoke(null, "qemu.hw.mainkeys");
            } catch (Throwable e) {
            }
        }
        return sNavBarOverride;
    }
}

2番目の方法:

 この方法には問題があります。これ以上は言いません


  /*  Rect rect = new Rect();
                rlAll.getWindowVisibleDisplayFrame(rect);
                int rootInvisibleHeight = rlAll.getRootView().getHeight() - rect.bottom;
                if (rootInvisibleHeight <= 100) {
                    //软键盘隐藏啦
                    btnNext.setVisibility(View.VISIBLE);
                } else {
                    软键盘弹出啦
                    btnNext.setVisibility(View.GONE);
                }*/

 

おすすめ

転載: blog.csdn.net/qq_36767261/article/details/81069353