“setSupportActionBar(toolbar)” inside FragmentActivity?

后端 未结 9 2113
被撕碎了的回忆
被撕碎了的回忆 2021-02-03 18:02

How do I access setSupportActionBar(Toolbar toolbar) inside FragmentActivity? I can\'t access it inside FragmentActivity

t         


        
相关标签:
9条回答
  • 2021-02-03 18:24

    If you want your ViewPager to add fragments, you can extend AppCompatActivity, it also works. (Often, we extend FragmentActivity, but after that setSupportActionBar( toolbar) doesn't work) So, we can extend AppCompatActivity instead of extending FragmentActivity.

    0 讨论(0)
  • 2021-02-03 18:24

    Instead of using setSupportActionBar use setActionBar Eg:

    android.widget.Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);    
    setActionBar(toolbar);
    
    0 讨论(0)
  • 2021-02-03 18:28

    You can just extend your class with AppCompatActivity, since AppCompatActivity extends FragmentActivity internally. Also, ActionBarActivity is deprecated.

    0 讨论(0)
  • 2021-02-03 18:31

    AppCompatActivity extends FragmentActivity

    public class AppCompatActivity extends FragmentActivity implements AppCompatCallback, SupportParentable, DelegateProvider
    

    you can use AppCompatActivity instead

    0 讨论(0)
  • 2021-02-03 18:33

    Use this methods your activity need to extend ActionBarActivity instead of FragmentActivity

    toolbar = (Toolbar) findViewById(R.id.search_bar);
    setSupportActionBar( toolbar);
    

    Hope it helps

    0 讨论(0)
  • 2021-02-03 18:34

    For FragmenrtActivity, you should look into FragmentTabHost, and to add tabs simply:

    tab = (FragmentTabHost)findViewById(android.R.id.tabhost);
    tab.setup(this, getSupportFragmentManager(), android.R.id.tabcontent);
    tab.addTab(tabs.newTabSpec("tab1").setIndicator("TAB1"), tab1.class, null);
    
    0 讨论(0)
提交回复
热议问题