为了账号安全,请及时绑定邮箱和手机立即绑定

当我触摸 AppCompatEditText 时,键盘是不可见的

当我触摸 AppCompatEditText 时,键盘是不可见的

慕妹3242003 2022-05-12 15:35:54
我创建了从 AppCompatEditText 扩展的类 ComplexEditText。我确定了我的背景变体: setBackground(getResources().getDrawable(R.drawable.backgroundedittext));我解决了填充:setPadding((int) (16 * scale), (int) (10 * scale), (int) (17 * scale), (int) (13 * scale));我创建了清除输入文本的按钮mClearButtonImage = ResourcesCompat.getDrawable(getResources(), R.mipmap.delete_button, null);但问题是当我触摸我的自定义视图(从 AppCompatEditText 扩展)时,键盘没有打开。我试过:setClickable(true)setFocusable(true)setShowSoftInputOnFocus(true);nputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);    imm.showSoftInput(this, InputMethodManager.SHOW_IMPLICIT);我在 AndroidManifes.xml 中安顿下来:android:windowSoftInputMode="adjustResize" 它也不起作用。键盘没有出现。AndroidManifest.xml    <?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    package="com.royallogistics.yegor.royallogistics">    <uses-permission android:name="android.permission.INTERNET" />    <uses-permission android:name="android.permission.READ_PHONE_STATE" />    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />    <application        android:name=".service.AppChannel"        android:allowBackup="true"        android:icon="@mipmap/ic_launcher"        android:label="@string/app_name"        android:roundIcon="@mipmap/ic_launcher_round"        android:supportsRtl="true"        android:theme="@style/AppTheme"        tools:ignore="GoogleAppIndexingWarning">        <activity android:name=".LoginActivity" />        <activity android:name=".SubordersDinamicsFields"            android:windowSoftInputMode="stateVisible">        </activity>
查看完整描述

1 回答

?
哔哔one

TA贡献1854条经验 获得超8个赞

我在构造函数中添加以下行:


clearFocus();

我在 onTouch 方法中添加以下代码:


                requestFocus();

                InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);

                imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);



查看完整回答
反对 回复 2022-05-12
  • 1 回答
  • 0 关注
  • 202 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号