2014-10-10 3 views
0

Я пробовал много ответов, но я не смог скрыть панель действий из фрагмента, она всегда отображается. Я не понимаю, почему, не могли бы вы мне помочь?Как скрыть панель действий в фрагменте заставки

Это мой код: Всплеск фрагмент:

public class SplashFragment extends Fragment { 



     @Override 
     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
      getActivity().getActionBar().hide(); 
      View view = inflater.inflate(R.layout.fragment_splash, container, false); 

      LoginButton authButton = (LoginButton) view.findViewById(R.id.login_button); 
      authButton.setReadPermissions(Arrays.asList("public_profile","email","user_friends")); 



      return view; 
     } 


    } 

Моя основная деятельность OnCreate метод:

@Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     //getWindow().requestFeature(Window.FEATURE_ACTION_BAR); 
     //getActionBar().hide(); 

     setContentView(R.layout.activity_main); 
     DebugHTTPRequests.enable(); 
} 

Мой стиль приложение Тема:

<!-- Application theme. --> 
    <style name="AppTheme" parent="AppBaseTheme"> 

     <!-- All customizations that are NOT specific to a particular API-level can go here. --> 
     <item name="android:actionBarStyle">@style/MyActionBar</item> 
     <item name="android:actionBarTabTextStyle">@style/MyActionBarTabText</item> 
     <item name="android:actionMenuTextColor">@color/mb_green</item> 
     <item name="android:actionOverflowButtonStyle">@style/OverflowMenuButton</item> 
     <item name="android:windowBackground">@color/white</item> 
     <item name="android:actionBarWidgetTheme">@style/PopupMenuTextView</item> 

    </style> 


    <style name="MyApp.actionBarWidgetTheme" parent="@style/AppTheme" > 
     <item name="android:spinnerDropDownItemStyle">@style/MyApp.Widget.DropDownItem.Spinner</item> 
    </style> 

    <style name="MyApp.Widget.DropDownItem.Spinner" parent="@android:style/Widget.DropDownItem.Spinner"> 
     <item name="android:textAppearance">@style/MyApp.TextAppearance.Widget.DropDownItem</item> 
    </style> 

    <style name="MyApp.TextAppearance.Widget.DropDownItem" parent="@android:style/TextAppearance.Widget.DropDownItem"> 
     <item name="android:textColor">@color/mb_green</item> 
    </style> 

    <!-- ActionBar styles --> 
    <style name="MyActionBar" parent="@android:style/Widget.Holo.ActionBar"> 
     <item name="android:background">@color/white</item> 
     <item name="android:titleTextStyle">@style/MyActionBarTitleText</item> 
    </style> 

    <!-- ActionBar title text --> 
    <style name="MyActionBarTitleText" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title"> 
     <item name="android:textColor">@color/mb_d_green</item> 
    </style> 

    <!-- ActionBar tabs text styles --> 
    <style name="MyActionBarTabText" parent="@android:style/Widget.Holo.ActionBar.TabText"> 
     <item name="android:textColor">@color/mb_green</item> 
    </style> 

    <!-- Over flow icon (3 carrés) --> 

    <style name="OverflowMenuButton" parent="@android:style/Widget.Holo.ActionButton.Overflow"> 
     <item name="android:src">@drawable/ic_fc_settings</item> 
    </style> 

    <!-- Change Overflow Menu ListView Text Size and Text Size --> 
    <style name="PopupMenuTextView" parent="@style/android:Theme.Holo.Light"> 
     <item name="android:textColor">@color/mb_green</item> 
     <item name="android:background">@color/transparent</item> 

    </style> 

Я не understant почему getActivity(). getActionBar(). hide() ничего не делает.

ответ

3

Попробуйте requestWindowFeature(Window.FEATURE_NO_TITLE);

Редактировать Как заявил @zgc7009, requestWindowFeature() должна вызываться перед setContentView()

+1

Я думаю, что это должно быть перед setContentView тоже нет? – zgc7009

+0

Да, в соответствии с документами «Это удобство для вызова getWindow(). RequestFeature()», а requestFeature необходимо вызывать перед setContentView http://developer.android.com/reference/android/view/Window.html# requestFeature (int) –

+0

Работает, но у меня есть только одно основное действие и 5 фрагментов, мне нужно просто скрыть фрагмент всплеска. Можно ли заниматься деятельностью после того, как появится панель действий? – WhatsUp

0

Наконец я изменить дизайн приложения, я создал activty (всплеск активности) перед моей основной деятельностью, и удалить фрагмент всплеска.

Он хорошо работает с requestWindowFeature (Window.FEATURE_NO_TITLE);

Спасибо!

0

Я думаю, что в фрагменте мы должны объявить folowing:

((AppCompatActivity) getActivity()).getSupportActionBar().show(); 
Смежные вопросы