2013-04-02

ActionBar one-line with tabs

Dùng tabs embedded để ép ActionBar hiển thị trên 1 dòng

Bài viết trên stackoverflow
http://stackoverflow.com/questions/12392541/replicate-actionbar-tabs-with-custom-view/12703960#12703960

Trên Google Group
https://groups.google.com/forum/#!topic/actionbarsherlock/hmmB1JqDeCk

Code dùng reflection


// Hide the home title
ActionBar bar = getSupportActionBar();
bar.setDisplayShowTitleEnabled(false);
// bar.setDisplayShowHomeEnabled(false);

// pre-ICS
if (bar instanceof ActionBarImpl) {
       enableEmbeddedTabs(bar);

       // ICS and forward
} else if (bar instanceof ActionBarWrapper) {
       try {
              Field actionBarField = bar.getClass().getDeclaredField(
                           "mActionBar");
              actionBarField.setAccessible(true);
              enableEmbeddedTabs(actionBarField.get(bar));
       } catch (Exception e) {
              LogUtils.e(TAG, "Error enabling embedded tabs", e);
       }
}

No comments:

Post a Comment