xuexiangjys / XUI

💍A simple and elegant Android native UI framework, free your hands! (一个简洁而优雅的Android原生UI框架,解放你的双手!)

Home Page:https://xuexiangjys.github.io/XUI/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

请教下编辑框的焦点事件问题怎么解决

guodun123 opened this issue · comments

问题一:
**MaterialEditText 焦点问题 **

<com.xuexiang.xui.widget.edittext.materialedittext.MaterialEditText
                android:id="@+id/input_login_name"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="36dp"
                android:hint="请输入账号"
                app:met_clearButton="true"
                app:met_floatingLabel="normal"
                app:met_floatingLabelText="用户名" />


在LoginFragment
  @Override
    protected void initViews() {
        binding.inputLoginName.requestFocus();
    }

界面虽然看的聚焦了,但是无法正常直接进行输入必须点一下输入框后才能输入

问题二:
SuperTextView 可编辑聚焦问题

  <com.xuexiang.xui.widget.textview.supertextview.SuperTextView
                android:id="@+id/input_bar_code"
                style="@style/EditInfoItem"
                app:sEnableEdit="true"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:inputType="text"
                app:sEditTextHint="请扫描商品条码"
                app:sLeftTextString="商品条码:" />

此控件问题一: binding.inputBarCode.getCenterEditText().requestFocus(); 同MaterialEditText 的问题
此控件问题二:此控件设置一个回车事件,校验输入的内容,代码如下

private void checkBarCode() {
        String scanBarCode = binding.inputBarCode.getCenterEditValue();
        if (StrUtil.isEmpty(scanBarCode)) {
            XToastUtils.error("请扫描条码");
            binding.inputBarCode.getCenterEditText().requestFocus();
        }
        if (!scanBarCode.equals(binding.productBarCode.getCenterString())) {
            XToastUtils.error("商品扫描错误");
            binding.inputBarCode.getCenterEditText().requestFocus();
        }
    }

无法正常聚焦

相关版本
versions.xui = "1.2.0"
versions.xupdate = "2.1.3"
versions.xaop = "1.1.0"
versions.xutil = "2.0.0"
versions.xhttp2 = "2.0.4"
versions.xpage = "3.4.0"
versions.xrouter = "1.1.0"

如何重现(必填)

  1. 写一个MaterialEditText 和SuperTextView控件,java类中设置requestFocus()
    启动项目即可重现

期望的效果
说明关于聚焦正确 具体的使用方式

设备信息
安卓模拟器:逍遥模拟器、雷电模拟器、蓝叠模拟器均进行了测试

  • Android版本: [ Android 7.0,android 9.0]
commented

这个焦点问题和MaterialEditText或者SuperTextView都没有关系.
主要是XUI的项目处理了键盘的显示模式,设置的都是stateHidden, 默认聚焦了也是无法直接拉起键盘的.
具体你可以到manifest里面去查看.

android:windowSoftInputMode="adjustPan|stateHidden"

你如果不想要这个逻辑的话, 可以去掉.

另外, SuperTextView的聚焦问题,直接使用SuperTextView去获取焦点即可,不需要getCenterEditText().requestFocus()