Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android hide title in fragment

I have started working in fragment. I am trying to hide titleBar in fragment, but i have this Log-cat Error

android fragment requestfeature must be called before adding content

this is a source

public class SendItemsFragment extends Fragment {

Button b1;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    getActivity().requestWindowFeature(Window.FEATURE_NO_TITLE);


    View rootView = inflater.inflate(R.layout.send_items, container, false);



    return rootView;
    }

}
like image 964
user3685293 Avatar asked Jun 12 '14 11:06

user3685293


Video Answer


2 Answers

This is what worked for me:

Hide action bar

((AppCompatActivity) getActivity()).getSupportActionBar().hide();
like image 124
nanaboison Avatar answered Sep 20 '22 16:09

nanaboison


You cannot call this method after setting contentView in Activity (LogCat answers your question already). You can do nothing about that. You must change your Fragment to Activity, or design your application in a different way. Eventually you can only hide title from Actionbar

getActivity().getActionBar().hide()
like image 21
Gaskoin Avatar answered Sep 16 '22 16:09

Gaskoin