本文整理匯總了Java中android.widget.TabHost.TabSpec方法的典型用法代碼示例。如果您正苦於以下問題:Java TabHost.TabSpec方法的具體用法?Java TabHost.TabSpec怎麽用?Java TabHost.TabSpec使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.widget.TabHost
的用法示例。
在下文中一共展示了TabHost.TabSpec方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: addTab
import android.widget.TabHost; //導入方法依賴的package包/類
public final void addTab(final TabHost.TabSpec tabSpec,
final Class<?> clss, final Bundle args) {
tabSpec.setContent(new DummyTabFactory(mContext));
String tag = tabSpec.getTag();
TabInfo info = new TabInfo(tag, clss, args);
if (mAttached) {
// If we are already attached to the window, then check to make
// sure this tab's fragment is inactive if it exists. This shouldn't
// normally happen.
info.fragment = mFragmentManager.findFragmentByTag(tag);
if (info.fragment != null && !info.fragment.isDetached()) {
FragmentTransaction ft = mFragmentManager.beginTransaction();
ft.detach(info.fragment);
ft.commit();
}
}
mTabs.add(info);
addTab(tabSpec);
}
示例2: createRotateTab
import android.widget.TabHost; //導入方法依賴的package包/類
private void createRotateTab(final LayoutInflater inflater, final ViewGroup container, final SeekBar.OnSeekBarChangeListener listener) {
TabHost.TabSpec spec;
spec = mTabHost.newTabSpec(getString(R.string.rotate_tab));
spec.setIndicator(createTabView(inflater, container, getString(R.string.rotate_title)));
spec.setContent(new TabHost.TabContentFactory() {
@Override
public View createTabContent(String tag) {
View view = inflater.inflate(R.layout.fragment_rotate, container, false);
mRotateSeekBar = (RangeSeekBar) view.findViewById(R.id.rotate_seekBar);
mRotateSeekBar.setRange(getResources().getIntArray(R.array.angle_seekbar_values));
mRotateSeekBar.setOnSeekBarChangeListener(listener);
return (view);
}
});
mTabHost.addTab(spec);
}
示例3: addTab
import android.widget.TabHost; //導入方法依賴的package包/類
private void addTab(final TabHost host, final int categoryId) {
final String tabId = EmojiCategory.getCategoryName(categoryId, 0 /* categoryPageId */);
final TabHost.TabSpec tspec = host.newTabSpec(tabId);
tspec.setContent(R.id.emoji_keyboard_dummy);
final ImageView iconView = (ImageView)LayoutInflater.from(getContext()).inflate(
R.layout.emoji_keyboard_tab_icon, null);
// TODO: Replace background color with its own setting rather than using the
// category page indicator background as a workaround.
iconView.setBackgroundColor(mCategoryPageIndicatorBackground);
iconView.setImageResource(mEmojiCategory.getCategoryTabIcon(categoryId));
iconView.setContentDescription(mEmojiCategory.getAccessibilityDescription(categoryId));
tspec.setIndicator(iconView);
host.addTab(tspec);
}
示例4: addTab
import android.widget.TabHost; //導入方法依賴的package包/類
private static void addTab(MFBMain activity, TabHost tabHost, TabHost.TabSpec tabSpec, TabInfo tabInfo) {
// Attach a Tab view factory to the spec
tabSpec.setContent(activity.new TabFactory(activity));
String tag = tabSpec.getTag();
// Check to see if we already have a fragment for this tab, probably
// from a previously saved state. If so, deactivate it, because our
// initial state is that a tab isn't shown.
tabInfo.fragment = activity.getSupportFragmentManager().findFragmentByTag(tag);
if (tabInfo.fragment != null && !tabInfo.fragment.isDetached()) {
FragmentTransaction ft = activity.getSupportFragmentManager().beginTransaction();
ft.detach(tabInfo.fragment);
ft.commit();
activity.getSupportFragmentManager().executePendingTransactions();
}
tabHost.addTab(tabSpec);
}
示例5: initTabs
import android.widget.TabHost; //導入方法依賴的package包/類
private void initTabs() {
MainTabs[] tabs = MainTabs.values();
for (MainTabs tab : tabs) {
TabHost.TabSpec tabSpec = mTabHost.newTabSpec(getString(tab.getNameRes()));
View indicator = inflateView(R.layout.view_tab_main_indicator);
ImageView icon = (ImageView) indicator.findViewById(R.id.tab_icon);
icon.setImageResource(tab.getIconRes());
TextView title = (TextView) indicator.findViewById(R.id.tab_titile);
title.setText(getString(tab.getNameRes()));
tabSpec.setIndicator(indicator);
tabSpec.setContent(new TabHost.TabContentFactory() {
@Override
public View createTabContent(String tag) {
return new View(MainActivity.this);
}
});
mTabHost.addTab(tabSpec, tab.getClazz(), null);
}
}
示例6: initView
import android.widget.TabHost; //導入方法依賴的package包/類
/**
* 初始化組件
*/
protected void initView(Bundle savedInstanceState) {
setContentView(R.layout.layout_bottomnavigation);
mTabHost = (MyFragmentTabHost) findViewById(R.id.tabhost);
//實例化布局對象
//實例化TabHost對象,得到TabHost
mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
// mTabHost.getTabWidget().setDividerDrawable(R.color.white);
// mTabHost.getTabWidget().setStripEnabled(true);
//得到fragment的個數
int count = getFragmentArray().length;
for (int i = 0; i < count; i++) {
//為每一個Tab按鈕設置圖標、文字和內容
TabHost.TabSpec tabSpec = mTabHost.newTabSpec(getTextviewArray()[i]).setIndicator(getTabItemView(i));
//將Tab按鈕添加進Tab選項卡中
mTabHost.addTab(tabSpec, getFragmentArray()[i], null);
//設置Tab按鈕的背景
mTabHost.getTabWidget().getChildAt(i).setBackgroundResource(R.color.bottom_color);
}
}
示例7: addTab
import android.widget.TabHost; //導入方法依賴的package包/類
public void addTab(TabHost.TabSpec tabSpec, Class<?> clss, Bundle args) {
tabSpec.setContent(new DummyTabFactory(mContext));
String tag = tabSpec.getTag();
TabInfo info = new TabInfo(tag, clss, args);
if (mAttached) {
// If we are already attached to the window, then check to make
// sure this tab's fragment is inactive if it exists. This shouldn't
// normally happen.
info.fragment = mFragmentManager.findFragmentByTag(tag);
if (info.fragment != null && !info.fragment.isDetached()) {
FragmentTransaction ft = mFragmentManager.beginTransaction();
// ft.detach(info.fragment);
ft.hide(info.fragment);
ft.commitAllowingStateLoss();
}
}
mTabs.add(info);
addTab(tabSpec);
}
示例8: setupTab
import android.widget.TabHost; //導入方法依賴的package包/類
protected void setupTab(TabHost tabHost, String text, int viewId, int tabId)
{
View tabview = LayoutInflater.from(tabHost.getContext()).inflate(tabId, null);
TextView tv = (TextView) tabview.findViewById(R.id.tabText);
tv.setText(text);
TabHost.TabSpec tab = tabHost.newTabSpec(text);
tab.setIndicator(tabview);
tab.setContent(viewId);
tabHost.addTab(tab);
}
示例9: onCreateView
import android.widget.TabHost; //導入方法依賴的package包/類
@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState);
final TabHost tabHost = (TabHost) view.findViewById(android.R.id.tabhost);
tabHost.setup();
// TabHost.TabSpec spec = tabHost.newTabSpec("Chat");
// spec.setIndicator("Chat");
// spec.setContent(new TabHost.TabContentFactory() {
// @Override
// public View createTabContent(String tag) {
// return inflater.inflate(R.layout.game_chat, null);
// }
// });
// tabHost.addTab(spec);
TabHost.TabSpec spec = tabHost.newTabSpec("Games");
spec.setIndicator("Games");
spec.setContent(new TabHost.TabContentFactory() {
@Override
public View createTabContent(String tag) {
return (new Button(getActivity()));
}
});
tabHost.addTab(spec);
return view;
}
示例10: initView
import android.widget.TabHost; //導入方法依賴的package包/類
private void initView() {
//測試欄目的題目統計TextView
mCount = (TextView) findViewById(R.id.tv_count);
mDoubleClickExit = new DoubleClickExitHelper(this);
Indicator[] indicators = Indicator.values();
mFragmentTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
mFragmentTabHost.setup(getApplicationContext(), getSupportFragmentManager(), R.id.realtabcontent);
//初始化Tab
for (int i = 0; i < indicators.length; i++){
TabHost.TabSpec tabSpec = mFragmentTabHost.newTabSpec(getString(indicators[i].getResName()));
tabSpec.setIndicator(getIndicatorView(indicators[i]));
mFragmentTabHost.addTab(tabSpec, indicators[i].getClz(), null);
}
//去除底部按鈕之間的分割線
if (android.os.Build.VERSION.SDK_INT > 10) {
mFragmentTabHost.getTabWidget().setShowDividers(0);
mFragmentTabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
@Override
public void onTabChanged(String tabId) {
if(tabId.equals(getString(Indicator.TEST.getResName()))){
mCount.setVisibility(View.VISIBLE);
}else{
mCount.setVisibility(View.GONE);
}
}
});
}}
示例11: setTabInfo
import android.widget.TabHost; //導入方法依賴的package包/類
private void setTabInfo() {
int count = fragmentArray.length;
mTabHost.setCurrentTab(0);
mTabHost.clearAllTabs();
for(int i=0;i<count; i++) {
TabHost.TabSpec tabSpec= mTabHost.newTabSpec(mTextviewArray[i]).setIndicator(getTabItemView(i));
mTabHost.addTab(tabSpec, fragmentArray[i], null);
}
}
示例12: onCreateView
import android.widget.TabHost; //導入方法依賴的package包/類
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
rootView= inflater.inflate(R.layout.fragment_first_aid, container, false);
viewPager = (ViewPager) rootView.findViewById(R.id.view_pager);
List<Fragment> listFragments = new ArrayList<Fragment>();
listFragments.add(new BurnsFragment());
listFragments.add(new CprFragment());
listFragments.add(new Fragment3());
viewPager.setOffscreenPageLimit(listFragments.size());
MyFragmentPagerAdapter myFragmentPagerAdapter = new MyFragmentPagerAdapter(getFragmentManager(),listFragments);
viewPager.setAdapter(myFragmentPagerAdapter);
viewPager.setOnPageChangeListener(this);
tabHost = (TabHost) rootView.findViewById(R.id.tabHost);
tabHost.setup();
String[] tabNames = {"Burns", "CPR", "Fire"};
for(int i=0; i<tabNames.length; i++){
TabHost.TabSpec tabSpec;
tabSpec = tabHost.newTabSpec(tabNames[i]);
tabSpec.setIndicator(tabNames[i]);
tabSpec.setContent(new FakeContent(getActivity().getApplicationContext()));
tabHost.addTab(tabSpec);
}
tabHost.setOnTabChangedListener(this);
return rootView;
}
示例13: getIndicator
import android.widget.TabHost; //導入方法依賴的package包/類
private TabHost.TabSpec getIndicator(Context context, TabHost.TabSpec spec,
String color, String str, int genResIcon) {
View v = LayoutInflater.from(context).inflate(R.layout.tab_item, null);
TextView tabText = (TextView) v.findViewById(R.id.tab_text);
ImageView tabImage = (ImageView) v.findViewById(R.id.tab_image);
v.setBackgroundColor(Color.parseColor(color));
tabText.setText(str);
tabText.setTextColor(Color.WHITE);
tabImage.setBackgroundResource(genResIcon);
return spec.setIndicator(v);
}
示例14: getNewTabSpec
import android.widget.TabHost; //導入方法依賴的package包/類
private TabHost.TabSpec getNewTabSpec(final View view, String title, int icon)
{
final TabHost.TabSpec tabSpec = tabHost.newTabSpec(title);
tabSpec.setContent(new TabHost.TabContentFactory()
{
public View createTabContent(String tag)
{
return view;
}
});
tabSpec.setIndicator("", ContextCompat.getDrawable(activity, icon));
return tabSpec;
}
示例15: setupTabs
import android.widget.TabHost; //導入方法依賴的package包/類
private void setupTabs() {
mTabHost.setup();
TabHost.TabSpec tabSpec;
tabSpec = mTabHost.newTabSpec(getString(R.string.stock_detail_tab1));
tabSpec.setIndicator(getString(R.string.stock_detail_tab1));
tabSpec.setContent(android.R.id.tabcontent);
mTabHost.addTab(tabSpec);
tabSpec = mTabHost.newTabSpec(getString(R.string.stock_detail_tab2));
tabSpec.setIndicator(getString(R.string.stock_detail_tab2));
tabSpec.setContent(android.R.id.tabcontent);
mTabHost.addTab(tabSpec);
tabSpec = mTabHost.newTabSpec(getString(R.string.stock_detail_tab3));
tabSpec.setIndicator(getString(R.string.stock_detail_tab3));
tabSpec.setContent(android.R.id.tabcontent);
mTabHost.addTab(tabSpec);
mTabHost.setOnTabChangedListener(this);
if (mSelectedTab.equals(getString(R.string.stock_detail_tab2))) {
mTabHost.setCurrentTab(1);
} else if (mSelectedTab.equals(getString(R.string.stock_detail_tab3))) {
mTabHost.setCurrentTab(2);
} else {
mTabHost.setCurrentTab(0);
}
}