我创建了从 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);
添加回答
举报
0/150
提交
取消