1.EditText 不弹出软件键盘
方法一:
在AndroidMainfest.xml中选择哪个activity,设置windowSoftInputMode属性为adjustUnspecified|stateHidden<activity android:name=".Main"
android:label="@string/app_name"
android:windowSoftInputMode="adjustUnspecified|stateHidden"
android:configChanges="orientation|keyboardHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<categoryandroid:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
例如:EditText edit=(EditText)findViewById(R.id.edit);edit.clearFocus();
例如:EditText edit=(EditText)findViewById(R.id.edit);
InputMethodManager imm =(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(edit.getWindowToken(),0);
2.EditText始终不弹出软件键盘
例:EditText edit=(EditText)findViewById(R.id.edit);edit.setInputType(InputType.TYPE_NULL);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE););//强制为横屏
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);//竖屏
横竖屏切换后Activity会重新执行onCreat函数,但是在Android工程的Mainfest.xml中加入android:screenOrientation="user" android:configChanges="orientation|keyboardHidden"之后,横竖屏切换之后就不会去执行OnCreat函数了,而是会去调用onConfigurationChanged(),这样我们就能控制横竖屏的切换了。
或者在res目录下建立layout-land和layout-port目录,相应的layout文件不变。layout-land是横屏的layout,layout-port是竖屏的layout。