在我的活动与滚动型布局和的EditText S初始状态时,的EditText 取值获得焦点和Android屏幕键盘打开。
我可以如何避免这种情况?
当我使用的LinearLayout 和 RelativeLayout的而不滚动型这不会发生。
我已经试过这种方式,和它的作品,但它不是一个好办法做到这一点:
TextView的TextFocus =(TextView中)findViewById(R.id.MovileLabel); TextFocus.setFocusableInTouchMode(真正的); TextFocus.requestFocus();
接下来你有我的一些布局这个问题,当这个活动开始一个例子,焦点转到第一个的EditText ,说明的和Android键盘会自动打开,这是很烦人的。
< XML版本=1.0编码=UTF-8&GT?; <滚动型机器人:ID =@ + ID / ScrollView01 机器人:layout_width =FILL_PARENT 机器人:layout_height =FILL_PARENT 的xmlns:机器人=http://schemas.android/apk/res/android> <的LinearLayout 机器人:方向=垂直 机器人:layout_width =FILL_PARENT 机器人:layout_height =FILL_PARENT 机器人:填充=10px的> < RelativeLayout的 机器人:重力=center_vertical 机器人:layout_width =FILL_PARENT 机器人:layout_height =WRAP_CONTENT> <的TextView 机器人:ID =@ + ID /编号userLabel 机器人:layout_width =WRAP_CONTENT 机器人:layout_height =WRAP_CONTENT 机器人:layout_marginTop =13px的 机器人:文本=@字符串/编号userLabel/> <的TextView 机器人:ID =@ + ID /用户 机器人:layout_alignBaseline =@ ID /编号userLabel 机器人:layout_alignParentRight =真 机器人:layout_width =WRAP_CONTENT 机器人:layout_height =WRAP_CONTENT 机器人:文本=测试/> < / RelativeLayout的> <查看 机器人:layout_gravity =center_horizontal 机器人:layout_width =FILL_PARENT 机器人:layout_height =1dip 机器人:后台=#808080 机器人:layout_marginTop =5像素 机器人:layout_marginBottom =12px的/> < RelativeLayout的 机器人:重力=center_vertical 机器人:layout_width =FILL_PARENT 机器人:layout_height =WRAP_CONTENT> <的TextView 机器人:ID =@ + ID / DescriptionLabel 机器人:layout_width =WRAP_CONTENT 机器人:layout_height =WRAP_CONTENT 机器人:文本=@字符串/ desclabel 机器人:layout_marginTop =13px的/> <的EditText 机器人:ID =@ + ID /说明 机器人:layout_alignBaseline =@ ID / DescriptionLabel 机器人:layout_alignParentRight =真 机器人:layout_width =WRAP_CONTENT 机器人:layout_height =WRAP_CONTENT 机器人:宽=180px/> < / RelativeLayout的> < RelativeLayout的 机器人:重力=center_vertical 机器人:layout_width =FILL_PARENT 机器人:layout_height =WRAP_CONTENT> <的TextView 机器人:ID =@ + ID / EmailLabel 机器人:layout_width =WRAP_CONTENT 机器人:layout_height =WRAP_CONTENT 机器人:文本=@字符串/ emaillabel 机器人:layout_marginTop =13px的/> <的EditText 机器人:ID =@ +帐号/电邮 机器人:layout_alignBaseline =@ + ID / EmailLabel 机器人:layout_alignParentRight =真 机器人:layout_width =WRAP_CONTENT 机器人:layout_height =WRAP_CONTENT 机器人:宽=180px/> < / RelativeLayout的> < RelativeLayout的 机器人:重力=center_vertical 机器人:layout_width =FILL_PARENT 机器人:layout_height =WRAP_CONTENT> <的TextView 机器人:ID =@ + ID / MovilePhoneLabel 机器人:layout_width =WRAP_CONTENT 机器人:layout_height =WRAP_CONTENT 机器人:文本=@字符串/ movilephonelabel 机器人:layout_marginTop =13px的/> <的EditText 机器人:ID =@ + ID / MovilePhone 机器人:layout_alignBaseline =@ + ID / MovilePhoneLabel 机器人:layout_alignParentRight =真 机器人:layout_width =WRAP_CONTENT 机器人:layout_height =WRAP_CONTENT 机器人:宽=180px/> < / RelativeLayout的> <查看 机器人:layout_gravity =center_horizontal 机器人:layout_width =FILL_PARENT 机器人:layout_height =1dip 机器人:后台=#808080 机器人:layout_marginTop =5像素 机器人:layout_marginBottom =10px的/> < RelativeLayout的 机器人:重力=center_vertical 机器人:layout_width =FILL_PARENT 机器人:layout_height =WRAP_CONTENT> <按钮 机器人:ID =@ + ID / applybutton 机器人:layout_width =WRAP_CONTENT 机器人:layout_height =WRAP_CONTENT 机器人:文本=@字符串/应用 机器人:WIDTH =100像素 机器人:layout_marginLeft =40dip/> <按钮 机器人:ID =@ + ID / cancelbutton 机器人:layout_width =WRAP_CONTENT 机器人:layout_height =WRAP_CONTENT 机器人:文本=@字符串/取消 机器人:WIDTH =100像素 机器人:layout_alignBaseline =@ + ID / applybutton 机器人:layout_alignParentRight =真 机器人:layout_marginRight =40dip/> < / RelativeLayout的> < / LinearLayout中> < /滚动型>解决方案
Android的自动打开OnScreenKeyboard如果你有一个的EditText 聚焦在活动开始时。
您可以prevent通过添加以下到您的活动的的onCreate 方法。
getWindow()。setSoftInputMode( WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);When my Activity with a ScrollView layout and EditTexts starts, the EditTexts get focus and the Android OnScreen keyboard opens.
How I can avoid that?
When I was using LinearLayout and RelativeLayout without the ScrollView it doesn't happen.
I've tried it this way, and it works, but it's not a good way to do it:
TextView TextFocus = (TextView) findViewById(R.id.MovileLabel); TextFocus.setFocusableInTouchMode(true); TextFocus.requestFocus();Next you have an example of some of my layouts with this problem, when this Activity starts, focus goes to the first EditText, Description and the Android keyboard opens automatically, this is very annoying.
<?xml version="1.0" encoding="utf-8"?> <ScrollView android:id="@+id/ScrollView01" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="schemas.android/apk/res/android"> <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="10px"> <RelativeLayout android:gravity="center_vertical" android:layout_width="fill_parent" android:layout_height="wrap_content"> <TextView android:id="@+id/UserLabel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="13px" android:text="@string/userlabel"/> <TextView android:id="@+id/User" android:layout_alignBaseline="@id/UserLabel" android:layout_alignParentRight="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="test"/> </RelativeLayout> <View android:layout_gravity="center_horizontal" android:layout_width="fill_parent" android:layout_height="1dip" android:background="#808080" android:layout_marginTop="5px" android:layout_marginBottom="12px"/> <RelativeLayout android:gravity="center_vertical" android:layout_width="fill_parent" android:layout_height="wrap_content"> <TextView android:id="@+id/DescriptionLabel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/desclabel" android:layout_marginTop="13px"/> <EditText android:id="@+id/Description" android:layout_alignBaseline="@id/DescriptionLabel" android:layout_alignParentRight="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:width="180px"/> </RelativeLayout> <RelativeLayout android:gravity="center_vertical" android:layout_width="fill_parent" android:layout_height="wrap_content"> <TextView android:id="@+id/EmailLabel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/emaillabel" android:layout_marginTop="13px"/> <EditText android:id="@+id/Email" android:layout_alignBaseline="@+id/EmailLabel" android:layout_alignParentRight="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:width="180px"/> </RelativeLayout> <RelativeLayout android:gravity="center_vertical" android:layout_width="fill_parent" android:layout_height="wrap_content"> <TextView android:id="@+id/MovilePhoneLabel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/movilephonelabel" android:layout_marginTop="13px"/> <EditText android:id="@+id/MovilePhone" android:layout_alignBaseline="@+id/MovilePhoneLabel" android:layout_alignParentRight="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:width="180px"/> </RelativeLayout> <View android:layout_gravity="center_horizontal" android:layout_width="fill_parent" android:layout_height="1dip" android:background="#808080" android:layout_marginTop="5px" android:layout_marginBottom="10px"/> <RelativeLayout android:gravity="center_vertical" android:layout_width="fill_parent" android:layout_height="wrap_content"> <Button android:id="@+id/applybutton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/apply" android:width="100px" android:layout_marginLeft="40dip"/> <Button android:id="@+id/cancelbutton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/cancel" android:width="100px" android:layout_alignBaseline="@+id/applybutton" android:layout_alignParentRight="true" android:layout_marginRight="40dip"/> </RelativeLayout> </LinearLayout> </ScrollView>解决方案
Android opens the OnScreenKeyboard automatically if you have an EditText focussed when the Activity starts.
You can prevent that by adding following into your Activity's onCreate method.
getWindow().setSoftInputMode( WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
更多推荐
屏幕键盘会自动打开活动开始时,
发布评论