WhatsUp
WhatsUp

Reputation: 463

How to hide Action bar in splash screen fragment

I tried a lot of answers, but I was not able to hide the action bar from a fragment, it is always showing. I don't understand why, could you help me please ?

This is my code : Splash fragment :

  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;
        }


    }

My main activity onCreate method :

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

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

My style app theme :

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

I don't understant why getActivity().getActionBar().hide() does nothing.

Upvotes: 0

Views: 2702

Answers (3)

Hai Ho
Hai Ho

Reputation: 1

I think that in Fragment we have to declare folowing :

((AppCompatActivity) getActivity()).getSupportActionBar().show();

Upvotes: 0

WhatsUp
WhatsUp

Reputation: 463

Finally i change my app design, i have created an activty (splash activity) before my main activity, and delete splash fragment.

It work well with requestWindowFeature(Window.FEATURE_NO_TITLE);

Thank you !

Upvotes: 0

Dave T.
Dave T.

Reputation: 1408

Try requestWindowFeature(Window.FEATURE_NO_TITLE);

Edit As stated by @zgc7009, requestWindowFeature() must be called before setContentView()

Upvotes: 3

Related Questions