“setSupportActionBar(toolbar)” inside FragmentActivity?

后端 未结 9 2131
被撕碎了的回忆
被撕碎了的回忆 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:36

    With the latest version of the support library you should make your Activity extend AppCompatActivity as ActionBarActivity has been deprecated.

    It provides the same functionality as your ActionBarActivity previously did. You shouldn't need to make any further changes.

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

    If your class extends FragmentActivity

    and if the toolbar is inside the layout you used, it will be set by default. To access it simply do

    (Toolbar) findViewById(R.id.toolbar)

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

    Use ActionBarActivity from support library, ActionBarActivity extends FragmentActivity, So that you can get SupportFragmentManager and set toolbar as actionbar

    Ex:

    public class MainActivity extends ActionBarActivity
    {
    
     Toolbar toolbar = (Toolbar) findViewById(R.id.search_bar);
     setSupportActionBar( toolbar);
    
     FragmentManager manager=this.getSupportFragmentManager();
    }
    
    0 讨论(0)
提交回复
热议问题