我知道你說你不能使用android:configChanges="keyboardHidden|orientation|screenSize"
因爲你有橫向和縱向不同的佈局,而是採取了看起來Android documentation關於處理配置改變自己:
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Checks the orientation of the screen
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
setContentView(R.layout.landscapeLayout);
//update your view elements, if any
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
setContentView(R.layout.portraitLayout);
//update your view elements, if any
}
}
這樣你可以維護您的不同佈局,並保留對您的對話框的引用
只需使用一個包並使用onSaveInstanceState – user2511882
嗨,@ user2511882。你能告訴我什麼是你建議我保存'onSaveInstanceState'方法嗎?我已經使用它來保存一個布爾值,說明是否顯示對話框... –