我想通过传感器更改我的活动方向,也可以通过操作按钮点击更改,但不能让它一起工作。
<activity
android:name=".activities.GraphActivity"
android:label="@string/app_name"
android:screenOrientation="sensor"
tools:replace="android:screenOrientation"
android:configChanges="keyboardHidden|orientation|screenSize" />
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
this.finish();
return true;
case R.id.action_orientation:
if (getResources().getConfiguration().orientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE )
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
else
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
default:
return super.onOptionsItemSelected(item);
}