Android 软键盘挡住输入框的问题

当在Android的layout设计里面若是输入框过多,则在输入弹出软键盘的时候,下面的输入框会有一部分被软件盘挡住,从而不能获取焦点输入。android

下面提供三种解决办法:布局

   方法一:在你的activity中的oncreate中setContentView以前写上这个代码getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);设计

   方法二:在 项目的AndroidManifest.xml文件中界面对应的<activity>里加入 android:windowSoftInputMode="stateVisible|adjustResize",这样会让屏幕总体上移。若是加上的 是 android:windowSoftInputMode="adjustPan"这样键盘就会覆盖屏幕。code

   方法三:把顶级的layout替换成ScrollView,或者说在顶级的Layout上面再加一层ScrollView的封装。这样就会把软键盘和输入框一块儿滚动了,软键盘会一直处于底部。xml

在咱们的LinearLayout布局外添加ScrollViewutf-8

 

方法三示例:get

 

由原来的:it

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
                                                                            
    ......
                                                                                
</LinearLayout>

改成:io

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
                                                                    
    ......
                                                                        
</LinearLayout>
</ScrollView>
相关文章
相关标签/搜索