Android 如何应对方向变化
我想在屏幕方向改变时显示祝酒词。我该怎么做呢?在if-else条件下,检查方向,这样你就可以随心所欲地展示吐司了Android 如何应对方向变化,android,orientation,Android,Orientation,我想在屏幕方向改变时显示祝酒词。我该怎么做呢?在if-else条件下,检查方向,这样你就可以随心所欲地展示吐司了 if (Intraday.this.getResources (). getConfiguration (). orientation == Configuration.ORIENTATION_PORTRAIT){ Toast.makeText(class.this, "msg", Toast.LENGTH_SHORT).show(); }
if (Intraday.this.getResources (). getConfiguration (). orientation == Configuration.ORIENTATION_PORTRAIT){
Toast.makeText(class.this, "msg", Toast.LENGTH_SHORT).show();
}
else if (Intraday.this.getResources (). getConfiguration (). orientation == Configuration.ORIENTATION_LANDSCAPE) {
Toast.makeText(class.this, "msg", Toast.LENGTH_SHORT).show();
}
vnsheety
您必须在该活动的AndroidManifest中添加以下内容:
android:configChanges="orientation"
然后,如果您覆盖函数onConfigurationChanged
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
//display toast here
}