Create action bar tabs from a snippet

Is it possible to create ActionBar tabs from a fragment?

I use the ABS library and have 2 fragments. The data in the second fragment changes dynamically and is it possible to dynamically display tabs from the fragment?

public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); for (int i = 1; i <= 3; i++) { ActionBar.Tab tab = getSupportActionBar().newTab(); tab.setText("Tab " + i); tab.setTabListener(this); getSupportActionBar().addTab(tab); } } 

This is the code that I have and I get The method getSupportActionBar() is undefined for the type

+4
source share
2 answers

never mind,

just used getSherlockActivity (). getSupportActionBar ()

Works great

+8
source

You need to give away your activity (say ActivityExtendsActionBarActivity ), which extends ActionBarActivity :

 ((ActivityExtendsActionBarActivity)getSupportActionBar()).setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); 
+2
source

Source: https://habr.com/ru/post/1445811/


All Articles