diff options
author | Jack Veenstra <veenstra@android.com> | 2009-06-01 21:27:01 -0700 |
---|---|---|
committer | Jack Veenstra <veenstra@android.com> | 2009-06-10 11:38:02 -0700 |
commit | 53175148c9b962c0ffe9cea0f3dc68bc0196e044 (patch) | |
tree | 169762ef55c30a9e5ccfa929c45c087c3cf51871 /core/java/android/widget/TabHost.java | |
parent | a32b5f3252a58416f328399680395aa5fa936640 (diff) | |
download | frameworks_base-53175148c9b962c0ffe9cea0f3dc68bc0196e044.zip frameworks_base-53175148c9b962c0ffe9cea0f3dc68bc0196e044.tar.gz frameworks_base-53175148c9b962c0ffe9cea0f3dc68bc0196e044.tar.bz2 |
Add support for custom tab views in TabHost and TabWidget.
This change adds the ability to specify an arbitrary view for a tab
indicator. It also adds support for specifying a drawable to use as
the divider between tab views.
Diffstat (limited to 'core/java/android/widget/TabHost.java')
-rw-r--r-- | core/java/android/widget/TabHost.java | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/core/java/android/widget/TabHost.java b/core/java/android/widget/TabHost.java index 5bf8035..103d44d 100644 --- a/core/java/android/widget/TabHost.java +++ b/core/java/android/widget/TabHost.java @@ -177,7 +177,7 @@ mTabHost.addTab(TAB_TAG_1, "Hello, world!", "Tab 1"); // leaving touch mode.. if nothing has focus, let's give it to // the indicator of the current tab if (!mCurrentView.hasFocus() || mCurrentView.isFocused()) { - mTabWidget.getChildAt(mCurrentTab).requestFocus(); + mTabWidget.getChildTabViewAt(mCurrentTab).requestFocus(); } } } @@ -197,6 +197,12 @@ mTabHost.addTab(TAB_TAG_1, "Hello, world!", "Tab 1"); } View tabIndicator = tabSpec.mIndicatorStrategy.createIndicatorView(); tabIndicator.setOnKeyListener(mTabKeyListener); + + // If this is a custom view, then do not draw the bottom strips for + // the tab indicators. + if (tabSpec.mIndicatorStrategy instanceof ViewIndicatorStrategy) { + mTabWidget.setDrawBottomStrips(false); + } mTabWidget.addView(tabIndicator); mTabSpecs.add(tabSpec); @@ -235,7 +241,7 @@ mTabHost.addTab(TAB_TAG_1, "Hello, world!", "Tab 1"); public View getCurrentTabView() { if (mCurrentTab >= 0 && mCurrentTab < mTabSpecs.size()) { - return mTabWidget.getChildAt(mCurrentTab); + return mTabWidget.getChildTabViewAt(mCurrentTab); } return null; } @@ -273,7 +279,7 @@ mTabHost.addTab(TAB_TAG_1, "Hello, world!", "Tab 1"); && (mCurrentView.isRootNamespace()) && (mCurrentView.hasFocus()) && (mCurrentView.findFocus().focusSearch(View.FOCUS_UP) == null)) { - mTabWidget.getChildAt(mCurrentTab).requestFocus(); + mTabWidget.getChildTabViewAt(mCurrentTab).requestFocus(); playSoundEffect(SoundEffectConstants.NAVIGATION_UP); return true; } @@ -411,6 +417,14 @@ mTabHost.addTab(TAB_TAG_1, "Hello, world!", "Tab 1"); } /** + * Specify a view as the tab indicator. + */ + public TabSpec setIndicator(View view) { + mIndicatorStrategy = new ViewIndicatorStrategy(view); + return this; + } + + /** * Specify the id of the view that should be used as the content * of the tab. */ @@ -437,7 +451,7 @@ mTabHost.addTab(TAB_TAG_1, "Hello, world!", "Tab 1"); } - String getTag() { + public String getTag() { return mTag; } } @@ -526,6 +540,22 @@ mTabHost.addTab(TAB_TAG_1, "Hello, world!", "Tab 1"); } /** + * How to create a tab indicator by specifying a view. + */ + private class ViewIndicatorStrategy implements IndicatorStrategy { + + private final View mView; + + private ViewIndicatorStrategy(View view) { + mView = view; + } + + public View createIndicatorView() { + return mView; + } + } + + /** * How to create the tab content via a view id. */ private class ViewIdContentStrategy implements ContentStrategy { |