视频全屏切换
LinearLayout linearLayout_search, linearLayout_progress, linearLayout_control;
TabHost tabHost;
TabWidget tabWidget;
ImageButton imageButton_fullscreen;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
linearLayout_search = findViewById(R.id.linearLayout_search);
linearLayout_progress = findViewById(R.id.linearLayout_progress);
linearLayout_control = findViewById(R.id.linearLayout_control);
tabHost = findViewById(R.id.tabHost);
tabWidget = tabHost.findViewById(android.R.id.tabs);
......
imageButton_fullscreen = findViewById(R.id.imageButton_fullscreen);
imageButton_fullscreen.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Configuration configuration = MainActivity.this.getResources().getConfiguration();
int orientation = configuration.orientation;
if (orientation == configuration.ORIENTATION_LANDSCAPE) {
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
linearLayout_search.setVisibility(View.VISIBLE);
linearLayout_progress.setVisibility(View.VISIBLE);
linearLayout_control.setVisibility(View.VISIBLE);
tabWidget.setVisibility(View.VISIBLE);
} else if (orientation == configuration.ORIENTATION_PORTRAIT) {
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
linearLayout_search.setVisibility(View.GONE);
linearLayout_progress.setVisibility(View.GONE);
linearLayout_control.setVisibility(View.GONE);
tabWidget.setVisibility(View.GONE);
}
}
});
......
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
Configuration configuration = MainActivity.this.getResources().getConfiguration();
int orientation = configuration.orientation;
if (orientation == configuration.ORIENTATION_LANDSCAPE) {
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
linearLayout_search.setVisibility(View.VISIBLE);
linearLayout_progress.setVisibility(View.VISIBLE);
linearLayout_control.setVisibility(View.VISIBLE);
tabWidget.setVisibility(View.VISIBLE);
} else if (orientation == configuration.ORIENTATION_PORTRAIT) {
moveTaskToBack(false);
}
return true;
}
return super.onKeyDown(keyCode, event);
}