Forcibly display Actionbar and Tab as one or two rows, actionbartab

Source: Internet
Author: User

Forcibly display Actionbar and Tab as one or two rows, actionbartab
Actionbar uses the Tab Mode

  • ActionBar. setNavigationMode (ActionBar. NAVIGATION_MODE_TABS) can be used as the navigation mode for another Actionbra;
  • ActionBar. addTab (Tab tab) use this method to add a specific Tab for your navigation;
Is it a single row or two rows?
  • According to the Developer's official Holo Design Guide, when the screen width is sufficient, the Tab will be embedded into the Actionbar and displayed as a line, such as when the screen Pad or mobile phone is landscape;
  • When the screen width is narrow, the Tab is displayed in the next line of the Actionbar, a total of two lines, common in mobile phone portrait;
Forcibly display as one or two rows in all cases
  • Sometimes the dual-line Tab needs to be displayed on the pad, or the single-line Actionbar needs to be displayed in the portrait screen of the mobile phone;
  • Forcibly display as a single row

  • try {          Method setHasEmbeddedTabsMethod = mActionBar.getClass().getDeclaredMethod(                  "setHasEmbeddedTabs", boolean.class);          setHasEmbeddedTabsMethod.setAccessible(true);          setHasEmbeddedTabsMethod.invoke(mActionBar, true);      } catch (Exception ignore) {      }
  • Forcibly display as two rows

  • try {          Method setHasEmbeddedTabsMethod = mActionBar.getClass().getDeclaredMethod(                  "setHasEmbeddedTabs", boolean.class);          setHasEmbeddedTabsMethod.setAccessible(true);          setHasEmbeddedTabsMethod.invoke(mActionBar, false);      } catch (Exception ignore) {      }

Use ActionbarSherlock
  • ActionbarSherlock directly calls Android native Actionbar in Android 3.0 and later versions, and uses built-in Actionbar for compatibility in Android 2.3 and later versions;
  • In the native class ActionBarWrapper, modify private final android. app. ActionBar mActionBar through reflection above;
  • In the compatible ActionBarImpl class, specify the parameter in setHasEmbeddedTabs (boolean hasEmbeddedTabs;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.