Skip to content Skip to sidebar Skip to footer

"setsupportactionbar(toolbar)" Inside Fragmentactivity?

How do I access setSupportActionBar(Toolbar toolbar) inside FragmentActivity? I can't access it inside FragmentActivity toolbar = (Toolbar) findViewById(R.id.search_bar); setSuppor

Solution 1:

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.

Solution 2:

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

Solution 3:

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

Ex:

publicclassMainActivityextendsActionBarActivity
{

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

 FragmentManager manager=this.getSupportFragmentManager();
}

Solution 4:

AppCompatActivity extends FragmentActivity

publicclassAppCompatActivityextendsFragmentActivityimplementsAppCompatCallback, SupportParentable, DelegateProvider

you can use AppCompatActivity instead

Solution 5:

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)

Post a Comment for ""setsupportactionbar(toolbar)" Inside Fragmentactivity?"