安卓解决EditText进入页面抢占焦点

版权声明:博主原创欢迎分享学习 https://blog.csdn.net/qXing123456789/article/details/83177409

安卓解决EditText进入页面抢占焦点

进入页面时,EditText会自动抢占焦点,弹出键盘,在一些交互上,比较影响用户体验,我们用2行代码来解决这个问题

1,在EditText父布局添加,这样父布局先于EditText夺取焦点,

android:focusable="true"
android:focusableInTouchMode="true"

a,focusable表示 移动光标时 是否能聚焦到组件上

b,focusableInTouchMode可以通过触摸获取焦点

完整XML代码

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:focusable="true"
                android:focusableInTouchMode="true">

                <EditText
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    />
            </RelativeLayout>

猜你喜欢

转载自blog.csdn.net/qXing123456789/article/details/83177409