Reputation: 151
I am creating an app with Facebook login feature. The main screen has two fragments which show up based on the login status. If you are not logged in, a home screen with a login button shows up, which has no Action Bar. If the user is logged in, Main Activity shows the welcome page, which has the action bar. I know that to hide action bar in an activity we can add android:theme="@android:style/Theme.DeviceDefault.NoActionBar.Fullscreen"
to that particular activity. But i do not want the ActionBar to disappear for the entire activity as I have to show it on the other fragment.
My question is: how do I show the action bar when the user is in logged in state, and the welcome screen fragment is shown?
Here is my code in the login fragment where I do not want the action bar:
public class LoginFragment extends Fragment{
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.login,
container, false);
//getActivity().getActionBar().hide();
return view;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onActivityCreated(savedInstanceState);
getActivity().getActionBar().hide();
}
}
The code for the Welcome Fragment where I want the Action BAr is as shown:
public class WelcomeFragment extends Fragment{
private static final String TAG = "WelcomeFragment";
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View view = inflater.inflate(R.layout.welcome,
container, false);
//getActivity().getActionBar().show();
return view;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onActivityCreated(savedInstanceState);
getActivity().getActionBar().show();
}
}
Upvotes: 0
Views: 416
Reputation: 3095
public class MyFragment extends Fragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
((YourActivity)getActivity()).getSupportActionBar().hide();
}
}
Upvotes: 0
Reputation: 323
you can hide and show action bar
getSupportActionBar().hide();
getSupportActionBar().show();
Upvotes: 1