I am having some trouble setting the sub-title in my Toolbar from my fragment. I keep getting a Null Pointer Exception at the setSubTitle.
@Override
public
You Can Create One Custom Layout For This And Then use in onCreateView method.
private ActionBar actionBar;
OnCreateView method:
actionBar = getActivity().getActionBar();
if (actionBar != null) {
actionBar.setCustomView(R.layout.actionbar_inner_custom_view);
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
}
Declare a variable ActionBar toolbar
and use it this way:
toolbar=((AppCompatActivity) getActivity()).getSupportActionBar();
toolbar.setHomeAsUpIndicator(R.drawable.ic_arrow_left);
toolbar.setTitle("Detalhes");
To use the Toolbar and the Appcompat 21, you have to use an AppCompatActivity and use:
((AppCompatActivity) getActivity()).getSupportActionBar().setSubtitle("About");
instead of calling getActivity() get the activity reference from the onAttach() lifecycle method of Fragment.
if you are using sherlock actionbar then call getSherlock().getActionBar()