有没有办法始终以纵向显示对话框?我需要它,因为它的布局。
我知道我可以为 Activity 设置它
android:screenOrientation="portrait|reversePortrait"
但是对话呢?
有没有办法始终以纵向显示对话框?我需要它,因为它的布局。
我知道我可以为 Activity 设置它
android:screenOrientation="portrait|reversePortrait"
但是对话呢?
在显示对话框时,检查设备的方向。
Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
int orientation = display.getOrientation();
//if orientation is portrait then show, if not then don't.
不确定这些方法是否符合您的要求,
一种方法是将 Activity 显示为屏幕方向设置为纵向(带有对话框主题)的对话框,请DialogActivity
参阅ApiDemos
另一种方法是通过以下方式强制活动改变其方向
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
并打开对话框onConfigurationChanged()
(有一些逻辑)。