Example usage for android.app ActionBar getClass

List of usage examples for android.app ActionBar getClass

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:com.example.android.tabbedroombookingtimetabledisplay.MainFragmentActivity.java

public void tabSettings(ActionBar actionBar) {
    try {/*from  ww w.j a v a  2  s. c  om*/

        actionBar.setHomeButtonEnabled(false);
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        final Method setHasEmbeddedTabsMethod = actionBar.getClass().getDeclaredMethod("setHasEmbeddedTabs",
                boolean.class);
        setHasEmbeddedTabsMethod.setAccessible(true);
        setHasEmbeddedTabsMethod.invoke(actionBar, false);

    } catch (final Exception e) {
        // Handle issues as needed: log, warn user, fallback etc
        // This error is safe to ignore, standard tabs will appear.
    }
}

From source file:co.nerdart.ourss.activity.MainActivity.java

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

    setContentView(activity_main);//from   w  w  w.j a va 2  s  . co  m

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

    // Hack to always show the tabs under the actionbar
    try {
        Method setHasEmbeddedTabsMethod = actionBar.getClass().getDeclaredMethod("setHasEmbeddedTabs",
                boolean.class);
        setHasEmbeddedTabsMethod.setAccessible(true);
        setHasEmbeddedTabsMethod.invoke(actionBar, false);
    } catch (Exception ignored) {
    }

    // Create the adapter that will return a fragment for each of the three
    // primary sections of the app.
    /*
     * The {@link android.support.v4.view.PagerAdapter} that will provide fragments for each of the sections. We use a {@link
    * android.support.v4.app.FragmentPagerAdapter} derivative, which will keep every loaded fragment in memory. If this becomes too memory
    * intensive, it may be best to switch to a {@link android.support.v4.app.FragmentStatePagerAdapter}.
    */
    SectionsPagerAdapter sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

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

    // 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);
            invalidateOptionsMenu(); // Do not do it into onTabSelected()!
        }
    });

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < sectionsPagerAdapter.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(sectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }

    if (PrefUtils.getBoolean(PrefUtils.REFRESH_ENABLED, true)) {
        // starts the service independent to this activity
        startService(new Intent(this, RefreshService.class));
    } else {
        stopService(new Intent(this, RefreshService.class));
    }
    if (PrefUtils.getBoolean(PrefUtils.REFRESH_ON_OPEN_ENABLED, false)) {
        if (!FetcherService.isRefreshingFeeds) {
            startService(new Intent(MainActivity.this, FetcherService.class)
                    .setAction(Constants.ACTION_REFRESH_FEEDS));
        }
    }

    getSupportLoaderManager().initLoader(loaderId, null, this);
}

From source file:com.embeddedlog.LightUpDroid.DeskClock.java

public void forceTabsInActionBar(final ActionBar actionBar) {
    try {/* ww  w . j  av  a2s . co m*/
        final Method setHasEmbeddedTabsMethod = actionBar.getClass().getDeclaredMethod("setHasEmbeddedTabs",
                boolean.class);
        setHasEmbeddedTabsMethod.setAccessible(true);
        setHasEmbeddedTabsMethod.invoke(actionBar, true);
    } catch (final Exception e) {
        // Safe to ignore exception, standard tabs will appear.
        Log.e(LOG_TAG, "Error enabling embedded tabs", e);
    }
}