Example usage for android.app ActionBar NAVIGATION_MODE_TABS

List of usage examples for android.app ActionBar NAVIGATION_MODE_TABS

Introduction

In this page you can find the example usage for android.app ActionBar NAVIGATION_MODE_TABS.

Prototype

int NAVIGATION_MODE_TABS

To view the source code for android.app ActionBar NAVIGATION_MODE_TABS.

Click Source Link

Document

Tab navigation mode.

Usage

From source file:com.example.jenil.parsedemo.GamePlayActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
    setContentView(R.layout.activity_game_play);

    Intent intent = getIntent();//from w ww. j a  v  a 2 s  .  c  o  m
    Phrase = intent.getStringExtra("MOVIE");
    words = Phrase.split(" ");

    opponent = intent.getStringExtra("OPPONENT");

    // Create the adapter that will return a fragment for each of the three primary sections
    // of the app.
    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager());

    // Set up the action bar.

    final ActionBar actionBar = getActionBar();

    if (actionBar == null) {
        Log.i("ALERT", "NULL");
    } else {
        Log.i("ALERT", "NOT NULL");
    }

    // Specify that the Home/Up button should not be enabled, since there is no hierarchical
    // parent.
    actionBar.setHomeButtonEnabled(false);

    // Specify that we will be displaying tabs in the action bar.
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Set up the ViewPager, attaching the adapter and setting up a listener for when the
    // user swipes between sections.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            // When swiping between different app sections, select the corresponding tab.
            // We can also use ActionBar.Tab#select() to do this if we have a reference to the
            // Tab.
            actionBar.setSelectedNavigationItem(position);
        }
    });

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mAppSectionsPagerAdapter.getCount() - 1; 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
        // listener for when this tab is selected.
        actionBar.addTab(
                actionBar.newTab().setText(mAppSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }
    actionBar.addTab(actionBar.newTab().setText("Submit").setTabListener(this));

}

From source file:org.monospace.smsfilter.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mTabs = new TabSet(NUM_TABS);
    mTabs.add(TAB_SMS, R.string.tab_sms_list, SMSListFragment.class);
    mTabs.add(TAB_FILTER, R.string.tab_filter_list, FilterListFragment.class);

    ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    actionBar.setDisplayShowTitleEnabled(false);

    ViewPager pager = new ViewPager(this);
    pager.setId(R.id.main_pager);//from w  ww  . j a v a 2 s . co m

    TabHelper helper = new TabHelper(this, pager);
    pager.setAdapter(helper);
    pager.setOnPageChangeListener(helper);

    for (TabSet.Tab t : mTabs) {
        Tab tab = actionBar.newTab().setText(t.textId).setTabListener(helper);
        actionBar.addTab(tab);
    }

    setContentView(pager);

    mReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            SMSListFragment fragment = (SMSListFragment) mTabs.getItem(TAB_SMS);
            fragment.refresh();
        }
    };

    registerReceiver(mReceiver, new IntentFilter("org.monospace.smsfilter.NEW_BLOCKED_SMS"));
}

From source file:com.github.hobbe.android.openkarotz.fragment.RadioFragment.java

@Override
public void onResume() {
    Log.v(LOG_TAG, "onResume");
    super.onResume();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
}

From source file:com.aniruddhc.acemusic.player.MusicLibraryEditorActivity.MusicLibraryEditorActivity.java

@SuppressWarnings("unchecked")
@Override// w w w. ja v a 2s.  c o  m
public void onCreate(Bundle savedInstanceState) {

    //Initialize Context and SharedPreferences.
    mContext = this;
    mApp = (Common) mContext.getApplicationContext();

    //Retrieve the name/icon of the library from the arguments.
    libraryName = getIntent().getExtras().getString("LIBRARY_NAME");
    libraryIconName = getIntent().getExtras().getString("LIBRARY_ICON");

    if (getIntent().getExtras().getSerializable("SONG_IDS_HASH_SET") != null) {
        songDBIdsList = (HashSet<String>) getIntent().getExtras().getSerializable("SONG_IDS_HASH_SET");
    }

    //Set the UI theme.
    if (mApp.getCurrentTheme() == Common.DARK_THEME) {
        setTheme(R.style.AppTheme);
    } else {
        setTheme(R.style.AppThemeLight);
    }
    super.onCreate(savedInstanceState);

    //Initialize the database helper.
    dbHelper = new DBAccessHelper(mContext.getApplicationContext());

    //Create a set of options to optimize the bitmap memory usage.
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    options.inJustDecodeBounds = false;
    options.inPurgeable = true;

    //Display Image Options.
    int defaultArt = UIElementsHelper.getIcon(mContext, "default_album_art_padded");
    displayImageOptions = new DisplayImageOptions.Builder().showImageForEmptyUri(R.drawable.default_album_art)
            .showImageOnFail(R.drawable.default_album_art).showStubImage(R.drawable.transparent_drawable)
            .cacheInMemory(false).cacheOnDisc(true).decodingOptions(options)
            .imageScaleType(ImageScaleType.EXACTLY).bitmapConfig(Bitmap.Config.RGB_565)
            .displayer(new FadeInBitmapDisplayer(400)).delayBeforeLoading(100).build();

    //Attach tabs to the ActionBar.
    ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    //Add the artists tab.
    String artistsLabel = getResources().getString(R.string.artists);
    Tab tab = actionBar.newTab();
    tab.setText(artistsLabel);
    TabListener<ArtistsPickerFragment> artistsTabListener = new TabListener<ArtistsPickerFragment>(this,
            artistsLabel, ArtistsPickerFragment.class);

    tab.setTabListener(artistsTabListener);
    actionBar.addTab(tab);

    //Add the albums tab.
    String albumsLabel = getResources().getString(R.string.albums);
    tab = actionBar.newTab();
    tab.setText(albumsLabel);
    TabListener<AlbumsPickerFragment> albumsTabListener = new TabListener<AlbumsPickerFragment>(this,
            albumsLabel, AlbumsPickerFragment.class);

    tab.setTabListener(albumsTabListener);
    actionBar.addTab(tab);

    //Add the songs tab.
    String songsLabel = getResources().getString(R.string.songs);
    tab = actionBar.newTab();
    tab.setText(songsLabel);
    TabListener<SongsPickerFragment> songsTabListener = new TabListener<SongsPickerFragment>(this, songsLabel,
            SongsPickerFragment.class);

    tab.setTabListener(songsTabListener);
    actionBar.addTab(tab);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        getWindow().setBackgroundDrawable(UIElementsHelper.getGeneralActionBarBackground(mContext));
        int topPadding = Common.getStatusBarHeight(mContext);
        View activityView = (View) findViewById(android.R.id.content);

        //Calculate ActionBar height
        TypedValue tv = new TypedValue();
        int actionBarHeight = 0;
        if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
            actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,
                    getResources().getDisplayMetrics());
        }

        if (activityView != null) {
            activityView.setPadding(0, topPadding + actionBarHeight, 0, 0);
        }

    }

}

From source file:info.curtbinder.farmgame.GameActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_game);

    new PlayMusicBackground().execute();

    fieldValues = getResources().getIntArray(R.array.itemFieldValues);
    fieldTitles = getResources().getStringArray(R.array.itemTitles);
    fieldSubTitles = getResources().getStringArray(R.array.itemSubTitles);
    Bundle b = getIntent().getExtras();//from   w w w  .  jav  a2  s.c  o m
    if (b != null) {
        gameId = b.getLong(GAMEID);
        gameDate = b.getString(GAMEDATE);
        gameName = b.getString(GAMENAME);
    }
    frags = new Fragment[MAX_FRAGS];

    // Set up the action bar.
    final ActionBar actionBar = getActionBar();
    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(getFragmentManager());

    // 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));
    }

    setActivityTitle(gameName);

}

From source file:org.ounl.lifelonglearninghub.fcube.navigate.SwipeFragmentActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_pager);

    // Create the adapter that will return a fragment for each of the three
    // primary sections
    // of the app.
    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager());

    // Set up the action bar.
    final ActionBar actionBar = getActionBar();

    // Specify that the Home/Up button should not be enabled, since there is
    // no hierarchical
    // parent.//w ww .j a v  a 2  s.c o  m
    actionBar.setHomeButtonEnabled(false);

    // Specify that we will be displaying tabs in the action bar.
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Set up the ViewPager, attaching the adapter and setting up a listener
    // for when the
    // user swipes between sections.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            // When swiping between different app sections, select
            // the corresponding tab.
            // We can also use ActionBar.Tab#select() to do this if
            // we have a reference to the
            // Tab.
            actionBar.setSelectedNavigationItem(position);
        }
    });

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mAppSectionsPagerAdapter.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
        // listener for when this tab is selected.
        actionBar.addTab(
                actionBar.newTab().setText(mAppSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }

}

From source file:com.example.android.listentgt.MainActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Create the adapter that will return a fragment for each of the three primary sections
    // of the app.
    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager());

    PACKAGE_NAME = getApplicationContext().getPackageName();

    // Set up the action bar.
    final ActionBar actionBar = getActionBar();

    // Specify that the Home/Up button should not be enabled, since there is no hierarchical
    // parent.//from  w  w  w.  java  2s .c om
    actionBar.setHomeButtonEnabled(false);

    // Specify that we will be displaying tabs in the action bar.
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Set up the ViewPager, attaching the adapter and setting up a listener for when the
    // user swipes between sections.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            // When swiping between different app sections, select the corresponding tab.
            // We can also use ActionBar.Tab#select() to do this if we have a reference to the
            // Tab.
            actionBar.setSelectedNavigationItem(position);
        }
    });

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mAppSectionsPagerAdapter.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
        // listener for when this tab is selected.
        actionBar.addTab(actionBar.newTab().setText(pages[i]).setTabListener(this));
    }

    //Initalize fragments
    fragment1 = new FragmentPlayList();
    fragment2 = new DeviceListFragment();
    fragment3 = new FragmentSettingsPage();

    //wifiP2pManagerActivity
    intentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION);
    intentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION);
    intentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);
    intentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION);

    manager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);
    channel = manager.initialize(this, getMainLooper(), null);
}

From source file:pl.bcichecki.rms.client.android.activities.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    actionBar = getActionBar();/*from www  . ja  v a2 s.  c  o  m*/
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    actionBar.setDisplayHomeAsUpEnabled(true);

    sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    viewPager = (ViewPager) findViewById(R.id.pager);
    viewPager.setAdapter(sectionsPagerAdapter);
    viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }
    });

    mainActivityActionBarTabListener = new MainActivityActionBarTabListener(viewPager);

    for (int i = 0; i < sectionsPagerAdapter.getCount(); i++) {
        Tab tab = actionBar.newTab();
        tab.setText(sectionsPagerAdapter.getPageTitle(i));
        tab.setTabListener(mainActivityActionBarTabListener);
        actionBar.addTab(tab);
    }
}

From source file:org.mariotaku.harmony.activity.MusicBrowserActivity.java

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setVolumeControlStream(AudioManager.STREAM_MUSIC);
    mImageLoader = HarmonyApplication.getInstance(this).getImageLoaderWrapper();
    mActionBar = getActionBar();// w  w w .j av a 2 s . c  o  m
    mActionBar.setDisplayShowTitleEnabled(false);
    //mActionBar.setDisplayShowHomeEnabled(false);
    mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    mPrefs = new PreferencesEditor(this);

    final String mount_state = Environment.getExternalStorageState();

    if (!Environment.MEDIA_MOUNTED.equals(mount_state)
            && !Environment.MEDIA_MOUNTED_READ_ONLY.equals(mount_state)) {
        startActivity(new Intent(this, ScanningProgress.class));
        finish();
    }

    setContentView(R.layout.music_browser);
    mSpinnerAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, android.R.id.text1);
    mSpinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mActionBar.setDisplayShowCustomEnabled(true);
    //mActionBar.setDisplayShowHomeEnabled(true);
    //mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
    //mActionBar.setListNavigationCallbacks(mSpinnerAdapter, this);
    mActionBar.setCustomView(R.layout.music_browser_control_bar);
    mControlContainer = mActionBar.getCustomView();
    //mViewPager.setEnabled(false);
    mAlbumArt = (AlbumArtView) mControlContainer.findViewById(R.id.album_art);
    mTrackName = (TextView) mControlContainer.findViewById(R.id.track_name);
    mTrackDetail = (TextView) mControlContainer.findViewById(R.id.track_detail);
    mPlayPauseButton = (ImageButton) mControlContainer.findViewById(R.id.play_pause);
    mNextButton = (ImageButton) mControlContainer.findViewById(R.id.next);
    mTabsAdapter = new TabsAdapter(this);
    mViewPager.setOnPageChangeListener(this);
    mViewPager.setOffscreenPageLimit(3);
    mViewPager.setAdapter(mTabsAdapter);
    mPlayPauseButton.setOnClickListener(this);
    mNextButton.setOnClickListener(this);
    configureTabs(!mViewPager.isEnabled());
    final int currenttab = mPrefs.getIntState(STATE_KEY_PAGE_POSITION_BROWSER, 0);
    mActionBar.setSelectedNavigationItem(currenttab);
}

From source file:org.dmfs.webcal.fragments.MyCalendarsFragment.java

private void setupActionBarTabs() {
    ActionBar actionBar = getActivity().getActionBar();

    int tabCount = actionBar.getTabCount();
    int pageCount = mAdapter.getCount();

    // replace titles and listeners of existing tabs
    int i = 0;//from  w  ww.j  a v  a2 s .c o  m
    for (; i < tabCount && i < pageCount; ++i) {
        final Tab tab = actionBar.getTabAt(i);
        tab.setText(mAdapter.getPageTitle(i));
        tab.setTabListener(this);
    }

    // add missing tabs
    for (; i < pageCount; ++i) {
        actionBar.addTab(actionBar.newTab().setText(mAdapter.getPageTitle(i)).setTabListener(this));
    }

    // remove remaining tabs
    for (; i < tabCount; --tabCount) {
        actionBar.removeTabAt(i);
    }
    if (pageCount > 1) {
        int selection = mSelectedTab;
        // changing the navigation mode might trigger a call to onTabSelected, overriding mSelectedTab with a wrong value, so save it
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        mSelectedTab = selection;
        if (selection < pageCount) {
            mViewPager.setCurrentItem(selection, false);
        }

    } else {
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
    }
}