Android不自动弹出软键盘和不让软键盘弹出挤压图形

软键盘弹出挤压图形很变态,设计好的模型会在软件盘弹出数据变得丑陋无比,为了保持不变,只需要在

Manifest.xml 相应的 Activity 里添加

android:windowSoftInputMode="adjustPan|stateHidden"

为了不让软件盘弹出,如果是Activity的话,可以直接添加如下代码解决自动弹出软键盘的问题

  <activity android:name="com.guandehao.baobiao.B_KuCunBaoBiao" 
            android:windowSoftInputMode="adjustPan|stateHidden"
            android:configChanges="orientation|keyboardHidden"/>

 还有就是不在Activity下的设置可能无效,如ActivityFragment,那直接可以使用下面这些方法,上面的设置可以保留。

第一种方法:

就是在不要弹出软件盘对应的EditText的父控件里添加

android:focusable="true"
android:focusableInTouchMode="true"

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:focusable="true"  
        android:focusableInTouchMode="true" 
    android:orientation="vertical" >

这是我感觉最方便的一个方法,也有人如下解决办法

这是第二种方法:

在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) view.findViewById(R.id.config_hidden);
        config_hidden.requestFocus();

我推荐使用第一种方法,简洁。

 

posted @ 2014-07-30 10:58  F_YuXiang  阅读(535)  评论(0编辑  收藏  举报