autojs 监听输入框键盘状态

发布于
88

[hidecontent type=”logged” desc=”隐藏内容:登录后可查看”]

"ui";

ui.layout(
    <vertical padding="16">
        <text text="输入框" textColor="black" textSize="16sp" marginTop="16"/>
        <input />
        
        <!-- hint属性用来设置输入框的提示-->
        <text text="带提示的输入框" textColor="black" textSize="16sp" marginTop="16"/>
        <input hint="请输入一些内容"/>
        
        <!-- inputType属性用来设置输入类型,包括number, email, phone等-->
        <text text="数字输入框" textColor="black" textSize="16sp" marginTop="16"/>
        <input inputType="number" text="123"/>
        
        <!-- password属性用来设置输入框是否是密码输入框 -->
        <text text="密码输入框" textColor="black" textSize="16sp" marginTop="16"/>
        <input password="true"/>
        
        <!-- lines属性用来设置输入框的行数 -->
        <text text="多行输入框" textColor="black" textSize="16sp" marginTop="16"/>
        <input lines="3"/>
        
        <text text="设置输入框错误信息" textColor="black" textSize="16sp" marginTop="16"/>
        <input id="qq" inputType="number" hint="请输入您的QQ号码"/>
        <button id="ok" text="确定" w="auto" style="Widget.AppCompat.Button.Colored"/>
    </vertical>
);

console.show()

activity.findViewById(android.R.id.content).addOnLayoutChangeListener({
    onLayoutChange: function(v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) {
        //if (bottom == oldBottom) return
        var decorView = activity.getWindow().getDecorView();
        var screenHeight = decorView.getHeight();
        var rect = new android.graphics.Rect();
        decorView.getWindowVisibleDisplayFrame(rect);
        var keyboardHeight = screenHeight - rect.bottom;
        var softShowing = keyboardHeight > screenHeight * 0.15;
        if (softShowing) {
            toastLog("键盘状态: 打开");
            // rootView.requestFocus();
        } else {
            toastLog("键盘状态: 关闭");
            activity.findViewById(android.R.id.content).clearFocus();
        }
    }
});

 

[/hidecontent]

 

0 点赞
0 收藏
分享
0 讨论
反馈
0 / 600
0 条评论
热门最新
嗨,下午好!
所有的成功,都源自一个勇敢的开始