I\'m trying to use the ActionBarSherlock library to provide backwards compatible ActionBar support with tabs in my Android app, so I downloaded the latest build, built the d
Another reason you might get null from getSupportActionBar()
is when the activity is used in a TabHost on Honeycomb+.
I make this mistake because i add the toobar in the fragment xml file. The code to find the toolbar in fragment is this:getActivity().findViewByid(id...),but my toolbar is in fragment xml file,so that there was no toolbar found and no toolbar beeing setSipprotActionBar() and also nothing get when getSupportActionBar(). So remember :Do not put the toolbar in your fragment`s xml file.
Depending how your write out code. ensure that you did set the toolbar first before calling it.
mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayShowHomeEnabled(true);
I had the same problem on the Android ICS 4.0.4. I was using requestWindowFeature(Window.FEATURE_NO_TITLE);
on the FragmentActivity, but this was hiding the ActionBar on ICS+ devices that caused the getSupportActionBar()
to be null.
Simply removed the:
requestWindowFeature(Window.FEATURE_NO_TITLE);
And it worked like a charm.
Hope it helps someone.
Heres a funny one: don't set the theme to -
android:theme="@style/Theme.NoActionbar"
whenever we set customview using sherlock library. just remove this requestWindowFeature(Window.FEATURE_NO_TITLE); like this we make customview using sherlock bar library..
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setCustomView(R.layout.header_sherlock_xmllayout);
header_tvleft = (TextView) findViewById(R.id.header_tvleft);
header_tvleft.setText("Back");