Android: getSupportActionBar() always returns null in ActionBarSherlock library

前端 未结 14 608
盖世英雄少女心
盖世英雄少女心 2020-11-29 05:29

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

相关标签:
14条回答
  • 2020-11-29 06:17

    Another reason you might get null from getSupportActionBar() is when the activity is used in a TabHost on Honeycomb+.

    0 讨论(0)
  • 2020-11-29 06:18

    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.

    0 讨论(0)
  • 2020-11-29 06:20

    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);
    
    0 讨论(0)
  • 2020-11-29 06:24

    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.

    0 讨论(0)
  • 2020-11-29 06:25

    Heres a funny one: don't set the theme to -

        android:theme="@style/Theme.NoActionbar"
    
    0 讨论(0)
  • 2020-11-29 06:25

    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");
    
    0 讨论(0)
提交回复
热议问题