以下是我的代码 我想设置它禁用自动更改屏幕方向 并启用自动更改屏幕方向。
class NewLoad extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
progDailog = new ProgressDialog(this);
progDailog.setMessage("test");
progDailog.setIndeterminate(false);
progDailog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progDailog.setCancelable(false);
progDailog.show();
//set disable auto change
}
@Override
protected String doInBackground(String... aurl) {
//do something
return null;
}
@Override
protected void onPostExecute(String unused) {
super.onPostExecute(unused);
progDailog.dismiss();
//set enable auto change
}
}
我该怎么办?
答案 0 :(得分:7)
让你的活动在清单
中看起来像这样 <activity
android:name=".Hello"
android:label="@string/app_name"
android:screenOrientation="portrait" <-- Screen will be forced to have portrait
android:configChanges="orientation|keyboardHidden|screensize" > <-- No Restart in these cases
ScreenSize属性似乎是在4.0中添加的,所以如果你要低于4.0,请不要提及它。
答案 1 :(得分:2)
disable auto change screen orientation.And enable auto change screen orientation.
如果你想at run time
尝试:
答案 2 :(得分:1)
在运行时:
当您想要阻止传感器时:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
当你想激活时:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
http://developer.android.com/reference/android/app/Activity.html