2012-04-10 5 views
3

私は自分のアプリケーションにActionbarsherlockを使用しています。私は自分のコードでアクションバーオーバーレイモードを切り替えるのが好きです。 私は2つのフラグメントを持っています(1つはMapviewで、半透明のアクションバーが必要です)。もう1つは、ソリッドなアクションバーが必要なListFragmentです。Actionbarsherlockスイッチアクションバーオーバーレイモードプログラム

私はこれで

requestWindowFeature((int) Window.FEATURE_ACTION_BAR & ~Window.FEATURE_ACTION_BAR_OVERLAY); 

問題はコンテンツが追加される前に、機能を要求するだけで動作することですしようと試みました。

iは透明アクションバー

<style name="TransparentActionbar" parent="@style/Theme.Sherlock" xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item name="windowActionBarOverlay">true</item> 
    <item name="windowActionModeOverlay">true</item> 
    <item name="abBackground">#96000000</item> 
    <item name="abDivider">@null</item> 
</style> 

/フラグメント活動の内側にはfalseに

<item name="windowActionBarOverlay">true</item> 
<item name="windowActionModeOverlay">true</item> 

を設定する方法がありますを達成するために、このスタイルを使用していますか?

答えて

3

編集:悲しいことに、これはActionbarsherlockと互換性パッケージのListFragmentでは機能しません。 上部マージンは何らかの理由でボトムマージンに追加されます。左と右のマージンは、LayoutListener内でうまく動作します。 Android Developer Example

// Attach a GlobalLayoutListener so that we get a callback when the layout 
// has finished drawing. This is necessary so that we can apply top-margin 
// to the ListView in order to dodge the ActionBar. Ordinarily, that's not 
// necessary, but we've set the ActionBar to "overlay" mode using our theme, 
// so the layout does not account for the action bar position on its own. 
ViewTreeObserver observer = getListView().getViewTreeObserver(); 
observer.addOnGlobalLayoutListener(layoutListener); 

// Because the fragment doesn't have a reliable callback to notify us when 
// the activity's layout is completely drawn, this OnGlobalLayoutListener provides 
// the necessary callback so we can add top-margin to the ListView in order to dodge 
// the ActionBar. Which is necessary because the ActionBar is in overlay mode, meaning 
// that it will ordinarily sit on top of the activity layout as a top layer and 
// the ActionBar height can vary. Specifically, when on a small/normal size screen, 
// the action bar tabs appear in a second row, making the action bar twice as tall. 
ViewTreeObserver.OnGlobalLayoutListener layoutListener = new ViewTreeObserver.OnGlobalLayoutListener() { 
    @Override 
    public void onGlobalLayout() { 
     int barHeight = getActivity().getActionBar().getHeight(); 
     ListView listView = getListView(); 
     FrameLayout.LayoutParams params = (LayoutParams) listView.getLayoutParams(); 
     // The list view top-margin should always match the action bar height 
     if (params.topMargin != barHeight) { 
      params.topMargin = barHeight; 
      listView.setLayoutParams(params); 
     } 
     // The action bar doesn't update its height when hidden, so make top-margin zero 
     if (!getActivity().getActionBar().isShowing()) { 
      params.topMargin = 0; 
      listView.setLayoutParams(params); 
     } 
    } 
}; 
+0

にこの問題の解決策を見つけた

はあなたに男をありがとうございました。あなたは私の問題を解決しました。 – tasomaniac

+1

偉大な発見、ちょうど私が必要なもの。読んでいる人にとってもう一つのことがあります。サンプルでは、​​onDestroyView()の 'ViewTreeObserver'から' OnGlobalLayoutListener'も削除します。このように: 'getListView()。getViewTreeObserver()。removeGlobalOnLayoutListener(mLayoutListener);'重要かもしれません。 –

関連する問題