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

我创建了从 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>


慕妹3242003
浏览 246回答 1
1回答

哔哔one

我在构造函数中添加以下行:clearFocus();我在 onTouch 方法中添加以下代码:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; requestFocus();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java