当我从纵向心情转到横向心情时,我想停止 Activity 刷新,并且当它从纵向心情转到横向心情时,我还想加载文件 layout-land 而不刷新 Activity 。
我使用 <activity android:name=".Login"
android:configChanges="orientation|screenSize">
但是,在这种方法中,当我从纵向转为横向时,它不会从 layout-land 文件夹中加载文件。我应该为此做什么?请有人帮助我。
最佳答案
在onConfigurationChanged()中调用方法setContentView(R.layout.main)
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
///in case you have some EditTexts , save their input before setting the new layout.
emailForConfigChanges = emailTextBox.getText().toString().trim();
passwordForConfigChanges = passwordTextBox.getText().toString().trim();
setContentView(R.layout.main);
//Now set the values back to the EditTexts .
}
您只需将此方法添加到您的 Activity 中,因为如果您在 list 中声明了“orientation”,它会处理所有方向更改。
编辑: 如果 EditTexts 在旋转时丢失它们的值,请在调用 onConfigurationChanged() 中的 setContentView() 之前获取它们的值。请参阅上面的编辑。
关于Android:当页面从纵向变为横向时停止刷新 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12794867/