How do I access setSupportActionBar(Toolbar toolbar)
inside FragmentActivity
?
I can't access it inside FragmentActivity
toolbar = (Toolbar) findViewById(R.id.search_bar);
setSupportActionBar( toolbar);
How do I access setSupportActionBar(Toolbar toolbar)
inside FragmentActivity
?
I can't access it inside FragmentActivity
toolbar = (Toolbar) findViewById(R.id.search_bar);
setSupportActionBar( toolbar);
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.
You can just extend your class with AppCompatActivity
, since AppCompatActivity extends FragmentActivity
internally. Also, ActionBarActivity
is deprecated.
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();
}
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)
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
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
.
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);
Instead of using setSupportActionBar use setActionBar Eg:
android.widget.Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setActionBar(toolbar);