use ActiconBar Sherlock library if you want twitter like application, link
ViewPager with icon only [closed]
-
30-06-2022 - |
質問
I'm trying to implement an ViewPager with the page title containing only an image/icon (Drawable).
I tried using J.W. ViewPagerIndicator, but it doesn't support icons only. The best I got is that I managed to display the icon, but is not centered(it is displayed on the left - like there is some text in the page title, but is not visible). I also tried to modify the library, but haven't managed to implement something that satisfies my needs for this (also I would prefer not to modify an library).
Can you guys recommend some other library or some good tutorial to implement custom ViewPager ?
PS: I'm trying to do something like the Twitter android application has.
Thank you.
LE:
After more searches and documentation I found that it can be achieved through reflection ... also I have found this method that works for now:
private void forceStackedTabs() {
ActionBar ab = getSupportActionBar();
if ( ab instanceof ActionBarImpl ) {
// Pre-ICS
disableEmbeddedTabs( ab );
} else if ( ab instanceof ActionBarWrapper ) {
// ICS
try {
Field abField = ab.getClass().getDeclaredField( "mActionBar" );
abField.setAccessible( true );
disableEmbeddedTabs( abField.get( ab ) );
} catch (NoSuchFieldException e) {
Log.e( TAG, "Error disabling actionbar embedded", e );
} catch (IllegalArgumentException e) {
Log.e( TAG, "Error disabling actionbar embedded", e );
} catch (IllegalAccessException e) {
Log.e( TAG, "Error disabling actionbar embedded", e );
}
}
}
private void disableEmbeddedTabs(Object ab) {
try {
Method setHasEmbeddedTabsMethod = ab.getClass().getDeclaredMethod("setHasEmbeddedTabs", boolean.class);
setHasEmbeddedTabsMethod.setAccessible(true);
setHasEmbeddedTabsMethod.invoke(ab, false);
} catch (Exception e) {
Log.e( TAG, "Error disabling actionbar embedded", e );
}
}
This is the link where I found it: forceStackedTabs()
But I would prefer another method, because through reflection this code can break at any time!
解決