我有在配置更改期间未重新创建的活动。在我的操作栏中,我有许多“ifroom”按钮。当活动以纵向模式创建时,其中一些会显示在操作栏中。在onConfigurationChanged()
I callgetActivity().invalidateOptionsMenu()
中,但在重新创建后,图标集与之前的屏幕方向相同。那么在这种情况下如何强制操作栏重新布局?
问问题
478 次
1 回答
0
On your res folder create inside values folder a new xml called bools like this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="nomal_layout">true</bool>
<bool name="nomal_layout_land">false</bool>
<bool name="large_layout">false</bool>
<bool name="large_layout_land">false</bool>
</resources>
the example above is for a normal portrait layout (true), create more values folders with bools.xml according with the layouts you want to customize, like values-large-land (or use the new buckets http://android-developers.blogspot.com.br/2011/07/new-tools-for-managing-screen-sizes.html). Then on the onCreateOptionsMenu you check the layout and force (SHOW_AS_ACTION_ALWAYS) the itens you want to show:
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.????, menu);//the menu to inflate
MenuItem myMenuItem = menu.findItem(R.id.????);//the item you want to show in the specified layout
if (getResources().getBoolean(R.bool.large_layout_land)){
myMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS)
}else{
}
This only works on Android >=11
于 2013-11-15T13:22:44.883 回答