2012-10-15 85 views
2

我有配置更改期間未重新創建的活動。在我的行動欄中,我有許多「ifroom」按鈕。在縱向模式下創建活動時,它們中的一些顯示在操作欄中。在我撥打電話getActivity().invalidateOptionsMenu(),但重新創建後,有一組圖標與以前的屏幕方向相同。那麼如何在這種情況下強制執行操作欄重新佈局?配置更改期間強制操作欄重新佈局

回答

0

在您的res文件夾內創建文件夾值一個新的XML這樣叫布爾變量:

<?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> 

上面的例子是一個正常的縱向佈局(真),創建具有根據以上bools.xml值的文件夾您想要自定義的佈局,如值大地(或使用新桶http://android-developers.blogspot.com.br/2011/07/new-tools-for-managing-screen-sizes.html)。然後在onCreateOptionsMenu你檢查的佈局和力(SHOW_AS_ACTION_ALWAYS)你要顯示的itens:

// 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{ 

} 

在Android> = 11

這隻能