How do I access setSupportActionBar(Toolbar toolbar)
inside FragmentActivity
?
I can\'t access it inside FragmentActivity
t
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
.
Instead of using setSupportActionBar use setActionBar Eg:
android.widget.Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setActionBar(toolbar);
You can just extend your class with AppCompatActivity
, since AppCompatActivity extends FragmentActivity
internally. Also, ActionBarActivity
is deprecated.
AppCompatActivity
extends FragmentActivity
public class AppCompatActivity extends FragmentActivity implements AppCompatCallback, SupportParentable, DelegateProvider
you can use AppCompatActivity
instead
Use this methods your activity need to extend ActionBarActivity instead of FragmentActivity
toolbar = (Toolbar) findViewById(R.id.search_bar);
setSupportActionBar( toolbar);
Hope it helps
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);