我已经设置了
android:configChanges="orientation"
android:screenOrientation="portrait"
在清单上,效果很好...直到出现键盘。当显示键盘时,您可以将方向更改为横向,而我的Web视图将刷新整个应用程序,使用户再次登录。我不需要(或不需要)保存状态,仅阻止在更改方向时可以刷新应用程序的全部功能。我不需要或不希望该应用程序能够打开横向屏幕。我不能完全只在肖像上使用,并为此而设计。
假设android:configChanges="orientation"
告诉android该应用将注意方向,并且android:screenOrientation="portrait"
在运行该应用时会阻止手机进入横向模式,但键盘似乎会覆盖此配置。
目前我还不知道如何实现此解决方法,
谢谢
已解决:
我尝试过android:configChanges =“ orientation | screenSize | screenLayout | keyboardHidden”
现在可以正常工作。我在documentation上找到了这条线,但乍一看,我认为我可能需要在configChanges上设置keyboardHidden后必须处理键盘显示/隐藏,但此选项可以正常使用,当用户与输入字段进行交互时键盘会出现,它无法在横向显示或将应用转到横向。我还根据链接的avobe建议的文档设置了screenSize和screenLayout。
我会尽可能将此问题标记为已解决。谢谢
保存状态。
private static final String STATE_COUNTER = "counter";
private int mCounter;
private ArrayList<Item> mItems;
@Override
protected void onSaveInstanceState(Bundle outState) {
// Make sure to call the super method so that the states of our views are saved
super.onSaveInstanceState(outState);
// Save our own state now
outState.putInt(STATE_COUNTER, mCounter);
// Save our own state now
outState.putSerializable(STATE_ITEMS, mItems);
}
然后再次恢复状态
private static final String STATE_COUNTER = "counter";
private TextView mCounterTextView;
private int mCounter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// If we have a saved state then we can restore it now
if (savedInstanceState != null) {
mCounter = savedInstanceState.getInt(STATE_COUNTER, 0);
}
// Display the value of the counter
mCounterTextView = (TextView) findViewById(R.id.counter_text);
mCounterTextView.setText(Integer.toString(mCounter));
...
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt(STATE_COUNTER, mCounter);
}
希望您找到答案。