我想在屏幕方向改变时显示一个Toast消息。我该怎么做?
答案 0 :(得分:4)
vnsheety,
您必须在AndroidManifest中为该活动添加以下内容:
android:configChanges="orientation"
然后,如果您覆盖函数onConfigurationChanged
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
//display toast here
}
答案 1 :(得分:3)
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();
}