【问题标题】:Android EditText doesn't show the KeyboardAndroid EditText 不显示键盘
【发布时间】:2013-08-23 05:37:45
【问题描述】:

我有一个带有三个 EditText 的屏幕,其中一个,第一个,在屏幕顶部,当我单击它时不会调用键盘。我没有使用 AVD,我使用的是自己的设备,并在其他设备上进行了测试,结果相同。

我将把屏幕和 xml 代码放在这里... EditTexts 之间没有什么不同,只是位置。 要在该 EditText 中进行输入,我需要选择上面的 EditText 之一,然后出现键盘。至少当我再次选择第一个 EditText 时它不会隐藏。 我已经尝试过 setFocus(true) 并没有解决我的问题。 请帮帮我!

XML

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".SaldoCadastro" >

<TextView
    android:id="@+id/tvTituloReg"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:text="Saldo Banco"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
    android:id="@+id/tvErroSenha1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/tvTituloReg"
    android:layout_marginTop="17dp"
    android:text="Insert on the field below how much you have in your bank." />

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/tvErroSenha1"
    android:layout_below="@+id/tvErroSenha1"
    android:layout_marginTop="41dp"
    android:text="Insert on the field below how much is your credit card limit." />

<EditText
    android:id="@+id/etSaldo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/tvErroSenha1"
    android:ems="10"
    android:inputType="numberDecimal" >

    <requestFocus />
</EditText>

<EditText
    android:id="@+id/etCartaoLimite"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/textView2"
    android:layout_below="@+id/textView2"
    android:ems="10"
    android:inputType="numberDecimal" />

<TextView
    android:id="@+id/textView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/etCartaoLimite"
    android:layout_below="@+id/etCartaoLimite"
    android:text="About your credt card how much you&apos;ve spent already." />

<EditText
    android:id="@+id/etCartao"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/textView3"
    android:layout_below="@+id/textView3"
    android:ems="10"
    android:inputType="numberDecimal" />

<Button
    android:id="@+id/btRegisterSaldo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/etCartao"
    android:layout_below="@+id/etCartao"
    android:layout_marginLeft="14dp"
    android:text="Register" />

【问题讨论】:

  • 我无法显示图像,因为我没有足够的声誉,对不起各位。

标签: android keyboard android-edittext


【解决方案1】:

从 xml 中删除这一行:

<requestFocus />

你可以在代码中添加这个:

editText.clearFocus();

【讨论】:

  • 我应该在所有 EditTexts 上添加 clearFocus() 还是仅在其中一个“损坏”?
  • 不管它在哪里不工作:)。您可以添加到所有。我认为在您的 xml 中,您仅将 添加到一个损坏的文件中。
  • 是的,我确实...尝试让它工作,阅读一些教程和其他答案,他们说这可以解决我的问题,但它没有。
【解决方案2】:

嘿,请检查您的AndroidManifest.xml 活动 并像这样在那里进行一些更改

android:windowSoftInputMode="stateAlwaysVisible"

在此布局示例的活动中:

<activity
    android:name="com.example.a.MainActivity"
    android:windowSoftInputMode="stateAlwaysVisible" // This will make your keyboard work
    android:label="@string/app_name" >

【讨论】:

    【解决方案3】:

    请在AndroidManifest.xml中添加属性android:windowSoftInputMode="adjustResize"

    <activity
        ......
        android:windowSoftInputMode="adjustResize">
    
        ...
    </activity>
    

    【讨论】:

    • 这个属性实际上是做什么的。
    • 投反对票,因为它根本无助于理解问题。只是说“做这个”,即使它有效,也不应该被赞成。
    【解决方案4】:

    你的意思是当你开始你的活动时,soft_keyboard 会出现吗?如果是这样,你所做的只是添加这个代码:

    android:windowSoftInputMode="adjustResize"
    

    发给你的AndroidManifest.xml,例如这样:

       <activity
            android:name="com.fortrun.testcrashlytics.MainActivity"
            android:label="@string/app_name"
            android:windowSoftInputMode="adjustResize" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
    
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    

    希望能帮到你!

    【讨论】:

      【解决方案5】:

      在我的情况下,使用 android EditText 而不是我的自定义 EditText 解决了这个问题。

      【讨论】:

        【解决方案6】:

        检查你的layout.xml,如果你的布局实现android:descendantFocusability="blocksDescendants"删除它

        【讨论】:

          猜你喜欢
          • 2021-01-27
          • 2019-03-21
          • 1970-01-01
          • 2014-10-05
          • 1970-01-01
          • 2012-12-15
          • 2020-09-30
          • 1970-01-01
          相关资源
          最近更新 更多