Constructors Summary |
---|
public TabHost(android.content.Context context)
super(context);
initTabHost();
|
public TabHost(android.content.Context context, android.util.AttributeSet attrs)
this(context, attrs, com.android.internal.R.attr.tabWidgetStyle);
|
public TabHost(android.content.Context context, android.util.AttributeSet attrs, int defStyleAttr)
this(context, attrs, defStyleAttr, 0);
|
public TabHost(android.content.Context context, android.util.AttributeSet attrs, int defStyleAttr, int defStyleRes)
super(context, attrs);
final TypedArray a = context.obtainStyledAttributes(
attrs, com.android.internal.R.styleable.TabWidget, defStyleAttr, defStyleRes);
mTabLayoutId = a.getResourceId(R.styleable.TabWidget_tabLayout, 0);
a.recycle();
if (mTabLayoutId == 0) {
// In case the tabWidgetStyle does not inherit from Widget.TabWidget and tabLayout is
// not defined.
mTabLayoutId = R.layout.tab_indicator_holo;
}
initTabHost();
|
Methods Summary |
---|
public void | addTab(android.widget.TabHost$TabSpec tabSpec)Add a tab.
if (tabSpec.mIndicatorStrategy == null) {
throw new IllegalArgumentException("you must specify a way to create the tab indicator.");
}
if (tabSpec.mContentStrategy == null) {
throw new IllegalArgumentException("you must specify a way to create the tab content");
}
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.setStripEnabled(false);
}
mTabWidget.addView(tabIndicator);
mTabSpecs.add(tabSpec);
if (mCurrentTab == -1) {
setCurrentTab(0);
}
|
public void | clearAllTabs()Removes all tabs from the tab widget associated with this tab host.
mTabWidget.removeAllViews();
initTabHost();
mTabContent.removeAllViews();
mTabSpecs.clear();
requestLayout();
invalidate();
|
public boolean | dispatchKeyEvent(android.view.KeyEvent event)
final boolean handled = super.dispatchKeyEvent(event);
// unhandled key events change focus to tab indicator for embedded
// activities when there is nothing that will take focus from default
// focus searching
if (!handled
&& (event.getAction() == KeyEvent.ACTION_DOWN)
&& (mCurrentView != null)
&& (mCurrentView.isRootNamespace())
&& (mCurrentView.hasFocus())) {
int keyCodeShouldChangeFocus = KeyEvent.KEYCODE_DPAD_UP;
int directionShouldChangeFocus = View.FOCUS_UP;
int soundEffect = SoundEffectConstants.NAVIGATION_UP;
switch (getTabWidgetLocation()) {
case TABWIDGET_LOCATION_LEFT:
keyCodeShouldChangeFocus = KeyEvent.KEYCODE_DPAD_LEFT;
directionShouldChangeFocus = View.FOCUS_LEFT;
soundEffect = SoundEffectConstants.NAVIGATION_LEFT;
break;
case TABWIDGET_LOCATION_RIGHT:
keyCodeShouldChangeFocus = KeyEvent.KEYCODE_DPAD_RIGHT;
directionShouldChangeFocus = View.FOCUS_RIGHT;
soundEffect = SoundEffectConstants.NAVIGATION_RIGHT;
break;
case TABWIDGET_LOCATION_BOTTOM:
keyCodeShouldChangeFocus = KeyEvent.KEYCODE_DPAD_DOWN;
directionShouldChangeFocus = View.FOCUS_DOWN;
soundEffect = SoundEffectConstants.NAVIGATION_DOWN;
break;
case TABWIDGET_LOCATION_TOP:
default:
keyCodeShouldChangeFocus = KeyEvent.KEYCODE_DPAD_UP;
directionShouldChangeFocus = View.FOCUS_UP;
soundEffect = SoundEffectConstants.NAVIGATION_UP;
break;
}
if (event.getKeyCode() == keyCodeShouldChangeFocus
&& mCurrentView.findFocus().focusSearch(directionShouldChangeFocus) == null) {
mTabWidget.getChildTabViewAt(mCurrentTab).requestFocus();
playSoundEffect(soundEffect);
return true;
}
}
return handled;
|
public void | dispatchWindowFocusChanged(boolean hasFocus)
if (mCurrentView != null){
mCurrentView.dispatchWindowFocusChanged(hasFocus);
}
|
public int | getCurrentTab()
return mCurrentTab;
|
public java.lang.String | getCurrentTabTag()
if (mCurrentTab >= 0 && mCurrentTab < mTabSpecs.size()) {
return mTabSpecs.get(mCurrentTab).getTag();
}
return null;
|
public android.view.View | getCurrentTabView()
if (mCurrentTab >= 0 && mCurrentTab < mTabSpecs.size()) {
return mTabWidget.getChildTabViewAt(mCurrentTab);
}
return null;
|
public android.view.View | getCurrentView()
return mCurrentView;
|
public FrameLayout | getTabContentView()Get the FrameLayout which holds tab content
return mTabContent;
|
public TabWidget | getTabWidget()
return mTabWidget;
|
private int | getTabWidgetLocation()Get the location of the TabWidget.
int location = TABWIDGET_LOCATION_TOP;
switch (mTabWidget.getOrientation()) {
case LinearLayout.VERTICAL:
location = (mTabContent.getLeft() < mTabWidget.getLeft()) ? TABWIDGET_LOCATION_RIGHT
: TABWIDGET_LOCATION_LEFT;
break;
case LinearLayout.HORIZONTAL:
default:
location = (mTabContent.getTop() < mTabWidget.getTop()) ? TABWIDGET_LOCATION_BOTTOM
: TABWIDGET_LOCATION_TOP;
break;
}
return location;
|
private void | initTabHost()
setFocusableInTouchMode(true);
setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
mCurrentTab = -1;
mCurrentView = null;
|
private void | invokeOnTabChangeListener()
if (mOnTabChangeListener != null) {
mOnTabChangeListener.onTabChanged(getCurrentTabTag());
}
|
public android.widget.TabHost$TabSpec | newTabSpec(java.lang.String tag)Get a new {@link TabSpec} associated with this tab host.
return new TabSpec(tag);
|
protected void | onAttachedToWindow()
super.onAttachedToWindow();
final ViewTreeObserver treeObserver = getViewTreeObserver();
treeObserver.addOnTouchModeChangeListener(this);
|
protected void | onDetachedFromWindow()
super.onDetachedFromWindow();
final ViewTreeObserver treeObserver = getViewTreeObserver();
treeObserver.removeOnTouchModeChangeListener(this);
|
public void | onInitializeAccessibilityEvent(android.view.accessibility.AccessibilityEvent event)
super.onInitializeAccessibilityEvent(event);
event.setClassName(TabHost.class.getName());
|
public void | onInitializeAccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo info)
super.onInitializeAccessibilityNodeInfo(info);
info.setClassName(TabHost.class.getName());
|
public void | onTouchModeChanged(boolean isInTouchMode){@inheritDoc}
if (!isInTouchMode) {
// leaving touch mode.. if nothing has focus, let's give it to
// the indicator of the current tab
if (mCurrentView != null && (!mCurrentView.hasFocus() || mCurrentView.isFocused())) {
mTabWidget.getChildTabViewAt(mCurrentTab).requestFocus();
}
}
|
public void | sendAccessibilityEvent(int eventType)
/* avoid super class behavior - TabWidget sends the right events */
|
public void | setCurrentTab(int index)
if (index < 0 || index >= mTabSpecs.size()) {
return;
}
if (index == mCurrentTab) {
return;
}
// notify old tab content
if (mCurrentTab != -1) {
mTabSpecs.get(mCurrentTab).mContentStrategy.tabClosed();
}
mCurrentTab = index;
final TabHost.TabSpec spec = mTabSpecs.get(index);
// Call the tab widget's focusCurrentTab(), instead of just
// selecting the tab.
mTabWidget.focusCurrentTab(mCurrentTab);
// tab content
mCurrentView = spec.mContentStrategy.getContentView();
if (mCurrentView.getParent() == null) {
mTabContent
.addView(
mCurrentView,
new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT));
}
if (!mTabWidget.hasFocus()) {
// if the tab widget didn't take focus (likely because we're in touch mode)
// give the current tab content view a shot
mCurrentView.requestFocus();
}
//mTabContent.requestFocus(View.FOCUS_FORWARD);
invokeOnTabChangeListener();
|
public void | setCurrentTabByTag(java.lang.String tag)
int i;
for (i = 0; i < mTabSpecs.size(); i++) {
if (mTabSpecs.get(i).getTag().equals(tag)) {
setCurrentTab(i);
break;
}
}
|
public void | setOnTabChangedListener(android.widget.TabHost$OnTabChangeListener l)Register a callback to be invoked when the selected state of any of the items
in this list changes
mOnTabChangeListener = l;
|
public void | setup()Call setup() before adding tabs if loading TabHost using findViewById().
However: You do not need to call setup() after getTabHost()
in {@link android.app.TabActivity TabActivity}.
Example:
mTabHost = (TabHost)findViewById(R.id.tabhost);
mTabHost.setup();
mTabHost.addTab(TAB_TAG_1, "Hello, world!", "Tab 1");
mTabWidget = (TabWidget) findViewById(com.android.internal.R.id.tabs);
if (mTabWidget == null) {
throw new RuntimeException(
"Your TabHost must have a TabWidget whose id attribute is 'android.R.id.tabs'");
}
// KeyListener to attach to all tabs. Detects non-navigation keys
// and relays them to the tab content.
mTabKeyListener = new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_CENTER:
case KeyEvent.KEYCODE_DPAD_LEFT:
case KeyEvent.KEYCODE_DPAD_RIGHT:
case KeyEvent.KEYCODE_DPAD_UP:
case KeyEvent.KEYCODE_DPAD_DOWN:
case KeyEvent.KEYCODE_ENTER:
return false;
}
mTabContent.requestFocus(View.FOCUS_FORWARD);
return mTabContent.dispatchKeyEvent(event);
}
};
mTabWidget.setTabSelectionListener(new TabWidget.OnTabSelectionChanged() {
public void onTabSelectionChanged(int tabIndex, boolean clicked) {
setCurrentTab(tabIndex);
if (clicked) {
mTabContent.requestFocus(View.FOCUS_FORWARD);
}
}
});
mTabContent = (FrameLayout) findViewById(com.android.internal.R.id.tabcontent);
if (mTabContent == null) {
throw new RuntimeException(
"Your TabHost must have a FrameLayout whose id attribute is "
+ "'android.R.id.tabcontent'");
}
|
public void | setup(android.app.LocalActivityManager activityGroup)If you are using {@link TabSpec#setContent(android.content.Intent)}, this
must be called since the activityGroup is needed to launch the local activity.
This is done for you if you extend {@link android.app.TabActivity}.
setup();
mLocalActivityManager = activityGroup;
|