zoukankan      html  css  js  c++  java
  • Android 禁止软键盘自动弹出

    Android系统对EditText这个控件有监听功能,如果某个Activity中含有该控件,就会自动弹出软键盘让你输入,这个看似人性化的方案有 时候并不被用户喜欢的,所以在有些情况下要禁用该功能。这几天做的应用也有这个问题,所以就查了,网上大部分都是如下方法:

    <activity android:name=".MainActivity"
                    android:screenOrientation="landscape"
                    <span style="color:#ff0000;">android:windowSoftInputMode="adjustPan|stateHidden"
    </span>                <span style="color:#ff0000;">android:configChanges="orientation|keyboardHidden</span>">         
                    <intent-filter>
                        <action android:name="android.intent.action.MAIN"/>
                        <category android:name="android.intent.category.LAUNCHER"/>
                    </intent-filter>       
         </activity> 

    该方法确实有用,但只是在刚进入此Activity时能起到左右,如果该Activity中有Tab功能的切换,软键盘又会弹出来,所以有了下面这个解决办法:

    在xml文件中加入一个隐藏的TextView:

    <TextView
            android:id="@+id/config_hidden"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:focusable="true"
            android:focusableInTouchMode="true"
            />

    然后再在Activity中加入:

    TextView config_hidden = (TextView) this.findViewById(R.id.config_hidden);
    config_hidden.requestFocus();

    这样软键盘就不会弹出了。

  • 相关阅读:
    LA 6439 Pasti Pas! Hash
    HDU 1067 Gap BFS+Hash
    POJ 3474 Gold Balanced Lineup Hash
    ZOJ 3802 Easy 2048 Again 状压DP
    Hihocoder #1044 状态压缩·一
    HDU 2522 & AOJ 441 & AOJ 364 关于小数和分数的转换
    HDU 2549 Sumset Hash+枚举
    POJ 1840 Eqs Hash + 中途相遇法
    HDU 2128 Tempter of the Bone II BFS
    POJ 3686 & 拆点&KM
  • 原文地址:https://www.cnblogs.com/zhujiabin/p/4757970.html
Copyright © 2011-2022 走看看