2

構成の変更中に再作成されないアクティビティがあります。私のアクションバーには、多くの「ifroom」ボタンがあります。アクティビティがポートレート モードで作成されると、それらのいくつかがアクションバーに表示されます。onConfigurationChanged()I callではgetActivity().invalidateOptionsMenu()、レクリエーションの後、以前の画面の向きと同じアイコンのセットがあります。では、そのような場合にアクションバーの再レイアウトを強制するにはどうすればよいですか?

4

1 に答える 1

0

res フォルダーで、values フォルダー内に bools という名前の新しい 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>

上記の例は、通常のポートレート レイアウト (true) の場合です。values-large-land など、カスタマイズしたいレイアウトに応じて、bools.xml でさらに値フォルダーを作成します (または、新しいバケットhttp://android-developers. blogspot.com.br/2011/07/new-tools-for-managing-screen-sizes.html )。次に、onCreateOptionsMenu でレイアウトを確認し、表示するアイテムを強制 (SHOW_AS_ACTION_ALWAYS) します。

// 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 でのみ機能します

于 2013-11-15T13:22:44.883 に答える