Search code examples
androidandroid-tabhostandroid-toolbarandroid-tabactivity

Android TabActivity with Toolbar - setSupportActionBar() unknow


Is it possible to use setSupportActionBar() in an TabActivity? Extending with AppCompatActivity is not possible...

public class TabHost extends TabActivity {

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tabhost);


        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar); // this is unkown
        getSupportActionBar().setDisplayHomeAsUpEnabled(true); //also

Do I have to switch from TabActivity to FragmentTabHost? Thanks


Solution

  • no you can't. You have to extend AppCompatActivity, and you shouldn't use TabActivity in the first place. It was deprecated long time ago. You should use a solution based on a ViewPager and Fragments to achieve the same behavior