How to hide auto show keyboard on layout gone

走远了吗. 提交于 2019-12-11 04:44:01

问题


i've a layout like:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@android:color/background_dark"
    android:weightSum="1" >

    <LinearLayout
        android:id="@+id/layout_splash"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_weight="0.3" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:src="@drawable/logo" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_marginTop="20dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.5"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/testoCaricamento"
            android:layout_gravity="center"
            android:textSize="20dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView" />

        <LinearLayout
            android:id="@+id/layoutNomeTablet"
            android:visibility="gone"
            android:layout_width="match_parent"
            android:layout_marginTop="40dp"
            android:layout_height="wrap_content"
            android:weightSum="1" >

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="right"
                android:textSize="20dp"
                android:layout_marginRight="15dp"
                android:layout_weight="0.2"
                android:text="Nome tablet" />

            <EditText
                android:id="@+id/editText1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="0.5" >

                <requestFocus />
            </EditText>

            <Button
                android:id="@+id/button1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="30dp"
                android:layout_weight="0.1"
                android:text="Salva" />

        </LinearLayout>

    </LinearLayout>

</LinearLayout>

When my splashscreen is shown, keyboard appears even if the layout that contain the EditText has visibility gone. how can i show keyboard only when edittext is visible and focused?


回答1:


Try making this change in your EditText.

<EditText
            android:id="@+id/editText1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight=""
</EditText>


来源:https://stackoverflow.com/questions/14377837/how-to-hide-auto-show-keyboard-on-layout-gone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!