Android 软件盘之使特定布局保持在软键盘之上

1.简述

本文将提及的是软键盘的使用技巧,包括一些初始进入的小细节还有一些常见的应用场景。

应用场景包括 1. 登陆注册界面时由于屏幕原因,弹出的软键盘会遮住登陆注册按钮

                       2.评论时输入文字框居于软件盘上的效果时

2.软件盘细节

      细节描述 

      1. 初次进入含有文本框的界面时,光标闪烁

       2. 软键盘弹出,页面跳转,可能导致抖动

       3. 软键盘将标题toolbar顶出去了

       解决方式       

       让EditText的父亲布局抢占其焦点,可以有效解决进入界面输入框光标闪烁问题

            <RelativeLayout
                android:layout_gravity="center_horizontal"
                android:layout_marginRight="35dp"
                android:layout_marginLeft="35dp"
                android:layout_marginTop="15dp"
                android:layout_width="match_parent"
                android:layout_height="35dp"
                android:id="@+id/account"
                android:focusable="true"           
                android:focusableInTouchMode="true"
                android:background="@drawable/bg_border_color_black"
                >
               .......
                <EditText
                    android:id="@+id/etAccount"
                    android:layout_width="match_parent"
                    android:textColor="@color/white"
                    android:layout_height="match_parent"
                    android:layout_marginLeft="10dp"
                    android:textColorHint="@color/white"
                    android:hint="请输入您的手机号"
                    android:textSize="13sp"
                    android:background="@null"
                    android:layout_marginRight="10dp"
                    android:layout_centerVertical="true"
                    android:layout_toEndOf="@+id/accountIcon"
                    tools:ignore="RtlCompat" />
            </RelativeLayout>

     延迟退出软键盘抗拒可能会出现的抖动

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            // 隐藏软键盘 imm.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), 0);
            // 延迟个0.1秒是因为 可能推出太快导致软键盘刚刚被回收,前面的界面出现断层
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
finish();

      规避底部的文本框不太接近弹出框的方法:

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <!-- *********** 核心,设置居于底部,paddingBottom 保持一定的距离**********-->
        <EditText
            android:layout_alignParentBottom="true"
            android:paddingLeft="10dp"
            android:paddingTop="10dp"
            android:paddingBottom="10dp"
            android:layout_marginTop="300dp"
            android:background="@drawable/bg_comment"
            android:layout_marginLe
  • 6
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值