Java Code Examples for android.support.v7.app.ActionBar#addTab()

The following examples show how to use android.support.v7.app.ActionBar#addTab() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: PinView   File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_activity);

    // Set up the action bar.
    final ActionBar actionBar = getSupportActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }
    });

    for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
        actionBar.addTab(
                actionBar.newTab()
                        .setText(mSectionsPagerAdapter.getPageTitle(i))
                        .setTabListener(this));
    }
}
 
Example 2
Source Project: sms-ticket   File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // setup actionbar tabs
    ActionBar bar = getSupportActionBar();
    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    bar.addTab(bar.newTab().setText(getString(R.string.tab_tickets)).setTabListener(mTabListener));
    bar.addTab(bar.newTab().setText(getString(R.string.tab_statistics)).setTabListener(mTabListener));
    if (savedInstanceState != null) {
        mSelectedTab = savedInstanceState.getInt("selectedTab", TAB_TICKETS);
    }
    bar.setSelectedNavigationItem(mSelectedTab);
    handleIntent(getIntent());
    UpdateService.call(this, false);
    checkForHigherPriorityReceivers();
    checkForSim();
    checkForEula();
}
 
Example 3
Source Project: ui   File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
private void setTabNavigation( ActionBar actionBar )
{
	actionBar.removeAllTabs();
	actionBar.setNavigationMode( ActionBar.NAVIGATION_MODE_TABS );
	actionBar.setTitle( R.string.app_name );

	Tab tab = actionBar
			.newTab()
			.setText( R.string.frag1 )
			.setTabListener(
					new MyTabListener( this, Fragment1.class.getName() ) );
	actionBar.addTab( tab );

	tab = actionBar
			.newTab()
			.setText( R.string.frag2 )
			.setTabListener(
					new MyTabListener( this, Fragment2.class.getName() ) );
	actionBar.addTab( tab );
	if (mSpinnerItem != null)
	{
		mSpinnerItem.setVisible( false );
	}
}
 
Example 4
Source Project: V.FlyoutTest   File: ActionBarDisplayOptions.java    License: MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.action_bar_display_options);

    findViewById(R.id.toggle_home_as_up).setOnClickListener(this);
    findViewById(R.id.toggle_show_home).setOnClickListener(this);
    findViewById(R.id.toggle_use_logo).setOnClickListener(this);
    findViewById(R.id.toggle_show_title).setOnClickListener(this);
    findViewById(R.id.toggle_show_custom).setOnClickListener(this);
    findViewById(R.id.toggle_navigation).setOnClickListener(this);
    findViewById(R.id.cycle_custom_gravity).setOnClickListener(this);
    findViewById(R.id.toggle_visibility).setOnClickListener(this);

    // Configure several action bar elements that will be toggled by display options.
    mCustomView = getLayoutInflater().inflate(R.layout.action_bar_display_options_custom, null);
    mCustomViewLayoutParams = new ActionBar.LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

    final ActionBar bar = getSupportActionBar();
    bar.setCustomView(mCustomView, mCustomViewLayoutParams);
    bar.addTab(bar.newTab().setText("Tab 1").setTabListener(this));
    bar.addTab(bar.newTab().setText("Tab 2").setTabListener(this));
    bar.addTab(bar.newTab().setText("Tab 3").setTabListener(this));
}
 
Example 5
Source Project: easy-adapter   File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(new MyPageAdapter(getSupportFragmentManager()));
    mViewPager.setOnPageChangeListener(mPageChangeListener);
    final ActionBar actionBar = getSupportActionBar();
    if (actionBar!= null) {
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        actionBar.addTab(actionBar
                .newTab()
                .setText(getString(R.string.tab_1_name))
                .setTabListener(mTabListener));
        actionBar.addTab(actionBar
                .newTab()
                .setText(getString(R.string.tab_2_name))
                .setTabListener(mTabListener));
    }
}
 
Example 6
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.about_main);

    // Set up the action bar.
    final ActionBar actionBar = getSupportActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Create the adapter that will return a fragment for each of the three
    // primary sections of the activity.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    // When swiping between different sections, select the corresponding
    // tab. We can also use ActionBar.Tab#select() to do this if we have
    // a reference to the Tab.
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }
    });

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
        // Create a tab with text corresponding to the page title defined by
        // the adapter. Also specify this Activity object, which implements
        // the TabListener interface, as the callback (listener) for when
        // this tab is selected.
        actionBar.addTab(
                actionBar.newTab()
                        .setText(mSectionsPagerAdapter.getPageTitle(i))
                        .setTabListener(this));
    }
}
 
Example 7
Source Project: support   File: MarkdownDemo.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_markdown_demo);

    // Set up the action bar.
    final ActionBar actionBar = getSupportActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Create the adapter that will return a fragment for each of the three
    // primary sections of the activity.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    // When swiping between different sections, select the corresponding
    // tab. We can also use ActionBar.Tab#select() to do this if we have
    // a reference to the Tab.
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }
    });

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
        actionBar.addTab(
                actionBar.newTab()
                        .setText(mSectionsPagerAdapter.getPageTitle(i))
                        .setTabListener(this));
    }
}
 
Example 8
@Override
protected void onCreate(Bundle savedInstanceState) {
	Log.i(TAG, "onCreate: " + savedInstanceState);
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_main_activity2);

	// Set up the action bar.
	final ActionBar actionBar = getSupportActionBar();
	actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

	mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

	int viewPagerItem = 0;
	if (null != savedInstanceState) {
		viewPagerItem = savedInstanceState.getInt("viewpage-current-item", 0);
	}

	Log.i(TAG, "viewPagerItem: " + viewPagerItem);

	mViewPager = (ViewPager) findViewById(R.id.pager);
	mViewPager.setAdapter(mSectionsPagerAdapter);

	mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
		@Override
		public void onPageSelected(int position) {
			actionBar.setSelectedNavigationItem(position);
		}
	});

	for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
		actionBar.addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
	}
}
 
Example 9
private void addLayoutTab(ActionBar actionBar, int layoutId, int iconId, String tag) {
    ActionBar.Tab tab = actionBar.newTab()
            .setText("")
            .setIcon(iconId)
            .setTabListener(new TabListener(layoutId, tag));
    actionBar.addTab(tab, layoutId == mSelectedLayoutId);
}
 
Example 10
Source Project: V.FlyoutTest   File: ActionBarTabs.java    License: MIT License 5 votes vote down vote up
public void onAddTab(View v) {
    final ActionBar bar = getSupportActionBar();
    final int tabCount = bar.getTabCount();
    final String text = "Tab " + tabCount;
    bar.addTab(bar.newTab()
            .setText(text)
            .setTabListener(new TabListener(new TabContentFragment(text))));
}
 
Example 11
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_view_pager_charts);

    // Set up the action bar.
    final ActionBar actionBar = getSupportActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Create the adapter that will return a fragment for each of the three
    // primary sections of the activity.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    // When swiping between different sections, select the corresponding
    // tab. We can also use ActionBar.Tab#select() to do this if we have
    // a reference to the Tab.
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }
    });

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
        // Create a tab with text corresponding to the page title defined by
        // the adapter. Also specify this Activity object, which implements
        // the TabListener interface, as the callback (listener) for when
        // this tab is selected.
        actionBar.addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }
}
 
Example 12
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sample_main);

    // Set the Action Bar to use tabs for navigation
    ActionBar ab = getSupportActionBar();
    ab.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Add three tabs to the Action Bar for display
    ab.addTab(ab.newTab().setText("Tab 1").setTabListener(this));
    ab.addTab(ab.newTab().setText("Tab 2").setTabListener(this));
    ab.addTab(ab.newTab().setText("Tab 3").setTabListener(this));
}
 
Example 13
@Override
protected void onCreate(Bundle savedInstanceState) {
    // createFontAwesomeEngine();
    IconicFontEngine.addDefaultEngine(
            new FontAwesomeEngine(Typeface.createFromAsset(getAssets(), "fonts/fontawesome-webfont.ttf")));
    IconicFontEngine.addDefaultEngine(
            new TypiconsEngine(Typeface.createFromAsset(getAssets(), "fonts/typicons.ttf")));

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Set up the action bar.
    final ActionBar actionBar = getSupportActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Create the adapter that will return a fragment for each of the three
    // primary sections of the activity.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    // When swiping between different sections, select the corresponding
    // tab. We can also use ActionBar.Tab#select() to do this if we have
    // a reference to the Tab.
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }
    });

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
        // Create a tab with text corresponding to the page title defined by
        // the adapter. Also specify this Activity object, which implements
        // the TabListener interface, as the callback (listener) for when
        // this tab is selected.
        actionBar.addTab(
                actionBar.newTab()
                        .setText(mSectionsPagerAdapter.getPageTitle(i))
                        .setTabListener(this));
    }
}
 
Example 14
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Fabric.with(this, new Crashlytics());
    setContentView(R.layout.activity_record_view);
    final ActionBar actionBar = getSupportActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // get current recording from intent
    if (getIntent() != null) {
        RecordingDB db = new RecordingDB(this);
        RecordViewActivity.currentRecord = db.getRecording(getIntent().getLongExtra(Recording.KEY, 0));
    }

    if (RecordViewActivity.currentRecord.getName() != null) {
        setTitle(RecordViewActivity.currentRecord.getName());
    } else {
        setTitle(RecordViewActivity.currentRecord.getDisplayDate(this));
    }

    // Create the adapter that will return a fragment for each of the three
    // primary sections of the activity.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    // When swiping between different sections, select the corresponding
    // tab. We can also use ActionBar.Tab#select() to do this if we have
    // a reference to the Tab.
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }
    });

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
        // Create a tab with text corresponding to the page title defined by
        // the adapter. Also specify this Activity object, which implements
        // the TabListener interface, as the callback (listener) for when
        // this tab is selected.
        actionBar.addTab(
                actionBar.newTab()
                        .setText(mSectionsPagerAdapter.getPageTitle(i))
                        .setTabListener(this));
    }
}