【问题标题】:Hide soft-keyboard or forcibly change the focus to hide the keyboard隐藏软键盘或强行改变焦点以隐藏键盘
【发布时间】:2015-08-10 04:40:15
【问题描述】:

我有一个相对布局的自定义列表视图,在我的一生中,我无法弄清楚为什么我的软键盘继续显示。根据我的研究,“默认”项目具有焦点,如果适用,软键盘将显示。在下一个活动开始之前有一个初始登录布局。当用户最初输入其凭据并尝试登录时,应显示软键盘。但是,下一个活动是我的 summary.xml,并且在用户登录后软键盘继续显示。我在这个网站上和搜索结果中尝试了几种不同的方法,但我认为问题可能与我的布局隔离。 如何在尝试登录后立即隐藏软键盘?

我在下面包含了我的 xml 布局。

登录.xml

<LinearLayout 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:gravity="center_horizontal"
    android:orientation="vertical" 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=".LoginActivity">

    <!-- Login progress -->
    <ProgressBar android:id="@+id/login_progress" style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:layout_marginBottom="8dp" android:visibility="gone" />

    <ScrollView android:id="@+id/login_form" android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout android:id="@+id/email_login_form" android:layout_width="match_parent"
            android:layout_height="wrap_content" android:orientation="vertical">

            <AutoCompleteTextView android:id="@+id/email" android:layout_width="match_parent"
                android:layout_height="wrap_content" android:hint="@string/prompt_email"
                android:inputType="textEmailAddress" android:maxLines="1"
                android:singleLine="true" />

            <EditText android:id="@+id/password" android:layout_width="match_parent"
                android:layout_height="wrap_content" android:hint="@string/prompt_password"
                android:imeActionId="@+id/login"
                android:imeActionLabel="@string/action_sign_in_short"
                android:imeOptions="actionUnspecified" android:inputType="textPassword"
                android:maxLines="1" android:singleLine="true" />

            <Button android:id="@+id/email_sign_in_button" style="?android:textAppearanceSmall"
                android:layout_width="match_parent" android:layout_height="wrap_content"
                android:layout_marginTop="16dp" android:text="@string/action_sign_in"
                android:textStyle="bold" />

        </LinearLayout>
    </ScrollView>

</LinearLayout>

summary.xml

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <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:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        android:paddingBottom="@dimen/activity_vertical_margin"
        tools:context="com.myapp.Summary">

        <TextView android:id="@+id/Welcome" android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <ListView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/mainListView"
            android:layout_below="@+id/Welcome"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_marginTop="21dp" />

    </RelativeLayout>

    <!-- Side navigation drawer UI -->
    <ListView
        android:id="@+id/navList"
        android:layout_width="200dp"
        android:layout_height="match_parent"
        android:layout_gravity="left|start"
        android:background="#ffeeeeee"/>

</android.support.v4.widget.DrawerLayout>

custom_listview.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:id="@+id/listView1"
    android:layout_height="match_parent"
    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=".LoginActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="Please wait.."
        android:layout_weight="1"
        android:id="@+id/txtFieldName" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="Please wait.."
        android:id="@+id/txtFieldValue" />
</LinearLayout>

【问题讨论】:

    标签: android xml keyboard android-softkeyboard


    【解决方案1】:

    我不太确定为什么上述方法不起作用,所以为了咯咯笑,我用谷歌搜索看看是否有“三星”特定的解决方案和 tada! (希望这不会破坏其他品牌。)

    How to hide keyboard for samsung galaxy note programmatically in android

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-12
      • 1970-01-01
      • 2011-02-17
      • 2017-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多