Android EditText
1.阻止进入界面就显示输入法:
在父layout设置获取焦点
android:focusable="true"
android:focusableInTouchMode="true"
或者
设置该EditText的焦点为false
或者
在manifest.xml中对应activity添加android:windowSoftInputMode="stateHidden"
2.键盘弹出时输入框被压缩
输入框获得焦点弹出软键盘时,输入框被压缩,字体上浮,同时背景出现问题。
网上解决方法是添加:
android:windowSoftInputMode="stateHidden|adjustResize"
或者
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
                             | WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
又或者
在外层布局中添加scrollView,因为scrollView只允许包含一个子View,所以如果出现问题布局已有外层layou,直接嵌套在ScrollView中即可,如下:
<ScrollView 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" > <!-- your layout --> </ScrollView>
或
<ScrollView 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" > <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" > <!-- your layout --> </RelativeLayout> </ScrollView>
3.设置边框:
不显示边框:
background="@null"
设置边框颜色及边框厚度:
在drawable中建一个xml文件:shape.xml
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <!-- 填充, android:color指定填充的颜色 --> <solid android:color="#00ff00ff"/> <!-- 圆角 --> <corners android:radius="8px"/> <!-- 描边 --> <stroke android:color="#32CD32" android:width="2px" /> <!-- 渐变,android:startColor和android:endColor分别为起始和结束颜色, android:angle是渐变角度,必须为45的整数倍。android:type渐变模式 --> <gradient android:startColor="#ff8c00" android:endColor="#FFFFFF" android:angle="270" /> </shape>
在控件中使用shape:background="@drawable/shape"
 
                    
                     
                    
                 
                    
                
 
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号