Java Code Examples for android.widget.TabHost#addTab()
The following examples show how to use
android.widget.TabHost#addTab() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LauncherActivity.java From android-apps with MIT License | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_launcher); TabHost tabHost = getTabHost(); TabSpec tab1 = tabHost.newTabSpec("First Tab"); TabSpec tab2 = tabHost.newTabSpec("Second Tab"); TabSpec tab3 = tabHost.newTabSpec("Third Tab"); tab1.setIndicator("Tab1",getResources().getDrawable(R.drawable.ic_launcher)); tab1.setContent(new Intent(this, Tab1Activity.class)); tab2.setIndicator("Tab2",getResources().getDrawable(R.drawable.ic_launcher)); tab2.setContent(new Intent(this, Tab2Activity.class)); tab3.setIndicator("Tab3",getResources().getDrawable(R.drawable.ic_launcher)); tab3.setContent(new Intent(this, Tab3Activity.class)); tabHost.addTab(tab1); tabHost.addTab(tab2); tabHost.addTab(tab3); }
Example 2
Source File: Tabs6.java From codeexamples-android with Eclipse Public License 1.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.tabs_right_gravity); final TabHost tabHost = getTabHost(); tabHost.addTab(tabHost.newTabSpec("tab1") .setIndicator("tab1", getResources().getDrawable(R.drawable.star_big_on)) .setContent(this)); tabHost.addTab(tabHost.newTabSpec("tab2") .setIndicator("tab2") .setContent(this)); tabHost.addTab(tabHost.newTabSpec("tab3") .setIndicator("tab3") .setContent(this)); }
Example 3
Source File: MessageListsActivity.java From medic-gateway with GNU Affero General Public License v3.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { log("Starting..."); super.onCreate(savedInstanceState); includeVersionNameInActivityTitle(this); TabHost tabHost = getTabHost(); String[] tabs = getResources().getStringArray(R.array.message_lists_tabs); for(int i=0; i<tabs.length; ++i) { TabHost.TabSpec spec = tabHost.newTabSpec(tabs[i]); spec.setIndicator(tabs[i]); spec.setContent(new Intent(this, TAB_CLASSES[i])); tabHost.addTab(spec); } updateForPollStatus(); LastPoll.register(this, pollUpdateReceiver); }
Example 4
Source File: EmojiPalettesView.java From openboard with GNU General Public License v3.0 | 5 votes |
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); }
Example 5
Source File: Tabs5.java From codeexamples-android with Eclipse Public License 1.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.tabs_scroll); final TabHost tabHost = getTabHost(); for (int i=1; i <= 30; i++) { String name = "Tab " + i; tabHost.addTab(tabHost.newTabSpec(name) .setIndicator(name) .setContent(this)); } }
Example 6
Source File: MainActivity.java From AndroidCacheFoundation with Apache License 2.0 | 5 votes |
private void showTabs() { initTabInfo(); tabHost = (TabHost) findViewById(android.R.id.tabhost); tabHost.setOnTabChangedListener(this); tabHost.setup(); viewPager = (MyViewPager) findViewById(R.id.viewpager); viewPager.setOffscreenPageLimit(5); viewPager.setAdapter(new TabAdapter(this, viewPager, tabInfos)); viewPager.setSwipeEnabled(false); for (TabInfo tabInfo : tabInfos) { TabHost.TabSpec tabSpec = tabHost.newTabSpec(tabInfo.getId()); tabSpec.setIndicator(tabInfo.getIndicatorView()); tabSpec.setContent(new TabHost.TabContentFactory() { @Override public View createTabContent(String arg0) { View v = new View(MainActivity.this); v.setMinimumWidth(0); v.setMinimumHeight(0); return v; } }); tabHost.addTab(tabSpec); } }
Example 7
Source File: TabHostDemo.java From ui with Apache License 2.0 | 5 votes |
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); test = "OnCreate"; Resources res = getResources(); // Resource object to get Drawables TabHost tabHost = getTabHost(); // The activity TabHost TabHost.TabSpec spec; // Resusable TabSpec for each tab Intent intent; // Reusable Intent for each tab // Create an Intent to launch an Activity for the tab (to be reused) intent = new Intent().setClass(this, tab1.class); // Initialize a TabSpec for each tab and add it to the TabHost spec = tabHost.newTabSpec("artists").setIndicator("Tab1")//, //res.getDrawable(R.drawable.ic_tab1)) .setContent(intent); tabHost.addTab(spec); // Do the same for the other tabs intent = new Intent().setClass(this, tab2.class); spec = tabHost.newTabSpec("albums").setIndicator("Albums") //, //res.getDrawable(R.drawable.ic_tab2)) .setContent(intent); tabHost.addTab(spec); intent = new Intent().setClass(this, tab3.class); spec = tabHost.newTabSpec("songs").setIndicator("Songs", res.getDrawable(R.drawable.ic_tab3)) .setContent(intent); tabHost.addTab(spec); tabHost.setCurrentTab(0); //first tab. }
Example 8
Source File: RMBTResultPagerFragment.java From open-rmbt with Apache License 2.0 | 5 votes |
private View createView(View v, LayoutInflater inflater, int currentPage) { tabHost = (TabHost) v.findViewById(android.R.id.tabhost); tabHost.setup(); tabHost.setOnTabChangedListener(this); for (int i = 0; i < pagerAdapter.getCount(); i++) { TabSpec tab = tabHost.newTabSpec(String.valueOf(i)); //tab.setIndicator(getActivity().getResources().getStringArray(R.array.result_page_title)[i]); tab.setContent(android.R.id.tabcontent); View indicator = inflater.inflate(R.layout.tabhost_indicator, null); TextView title = (TextView) indicator.findViewById(android.R.id.title); title.setText(getActivity().getResources().getStringArray(R.array.result_page_title)[RMBTResultPagerAdapter.RESULT_PAGE_TAB_TITLE_MAP.get(i)]); if (MAP_INDICATOR_DYNAMIC_VISIBILITY) { if (i == RMBTResultPagerAdapter.RESULT_PAGE_MAP) { indicator.setVisibility(View.GONE); } } tab.setIndicator(indicator); tabHost.addTab(tab); } scroller = (HorizontalScrollView) v.findViewById(R.id.tabwidget_scrollview); viewPager = (ExtendedViewPager) v.findViewById(R.id.pager); viewPager.setAdapter(pagerAdapter); viewPager.setOnPageChangeListener(this); setCurrentPosition(currentPage); return v; }
Example 9
Source File: MainActivity.java From financisto with GNU General Public License v2.0 | 5 votes |
private void setupBlotterTab(TabHost tabHost) { Intent intent = new Intent(this, BlotterActivity.class); intent.putExtra(BlotterActivity.SAVE_FILTER, true); intent.putExtra(BlotterActivity.EXTRA_FILTER_ACCOUNTS, true); tabHost.addTab(tabHost.newTabSpec("blotter") .setIndicator(getString(R.string.blotter), getResources().getDrawable(R.drawable.ic_tab_blotter)) .setContent(intent)); }
Example 10
Source File: EmojiPalettesView.java From Indic-Keyboard with Apache License 2.0 | 5 votes |
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); }
Example 11
Source File: DocActivityView.java From Mupdf with Apache License 2.0 | 5 votes |
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); }
Example 12
Source File: IMPopupDialog.java From opensudoku with GNU General Public License v3.0 | 5 votes |
/** * Creates view with two tabs, first for number in cell selection, second for * note editing. * * @return */ private TabHost createTabView() { TabHost tabHost = new TabHost(mContext, null); tabHost.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); //tabHost.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); LinearLayout linearLayout = new LinearLayout(mContext); linearLayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); //linearLayout.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); linearLayout.setOrientation(LinearLayout.VERTICAL); TabWidget tabWidget = new TabWidget(mContext); tabWidget.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); tabWidget.setId(android.R.id.tabs); FrameLayout frameLayout = new FrameLayout(mContext); frameLayout.setId(android.R.id.tabcontent); linearLayout.addView(tabWidget); linearLayout.addView(frameLayout); tabHost.addView(linearLayout); tabHost.setup(); final View editNumberView = createEditNumberView(); final View editNoteView = createEditNoteView(); tabHost.addTab(tabHost.newTabSpec("number") .setIndicator(mContext.getString(R.string.select_number)) .setContent(tag -> editNumberView)); tabHost.addTab(tabHost.newTabSpec("note") .setIndicator(mContext.getString(R.string.edit_note)) .setContent(tag -> editNoteView)); return tabHost; }
Example 13
Source File: TabTestActivity.java From ans-android-sdk with GNU General Public License v3.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_tabhost); //获取该activity里面的TabHost组件 TabHost tabhost=getTabHost(); //创建第一个tab页对象,TabSpec代表一个选项卡页面,要设置标题和内容,内容是布局文件中FrameLayout中 TabHost.TabSpec tab1=tabhost.newTabSpec("tab1"); tab1.setIndicator("已接电话");//设置标题 tab1.setContent(R.id.tab01);//设置内容 //添加tab页 tabhost.addTab(tab1); //创建第二个tab页对象 TabHost.TabSpec tab2=tabhost.newTabSpec("tab1"); tab2.setIndicator("已拨电话");//设置标题 tab2.setContent(R.id.tab02);//设置内容 //添加tab页 tabhost.addTab(tab2); //创建第三个tab页对象 TabHost.TabSpec tab3=tabhost.newTabSpec("tab1"); tab3.setIndicator("未接电话");//设置标题 tab3.setContent(R.id.tab03);//设置内容 //添加tab页 tabhost.addTab(tab3); }
Example 14
Source File: MainActivity.java From financisto with GNU General Public License v2.0 | 4 votes |
private void setupAccountsTab(TabHost tabHost) { tabHost.addTab(tabHost.newTabSpec("accounts") .setIndicator(getString(R.string.accounts), getResources().getDrawable(R.drawable.ic_tab_accounts)) .setContent(new Intent(this, AccountListActivity.class))); }
Example 15
Source File: MainActivity.java From financisto with GNU General Public License v2.0 | 4 votes |
private void setupReportsTab(TabHost tabHost) { tabHost.addTab(tabHost.newTabSpec("reports") .setIndicator(getString(R.string.reports), getResources().getDrawable(R.drawable.ic_tab_reports)) .setContent(new Intent(this, ReportsListActivity.class))); }
Example 16
Source File: MainActivity.java From financisto with GNU General Public License v2.0 | 4 votes |
private void setupMenuTab(TabHost tabHost) { tabHost.addTab(tabHost.newTabSpec("menu") .setIndicator(getString(R.string.menu), getResources().getDrawable(R.drawable.ic_tab_menu)) .setContent(new Intent(this, MenuListActivity_.class))); }
Example 17
Source File: DisplayAlternativeNovelPagerActivity.java From coolreader with MIT License | 4 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { UIHelper.SetTheme(this, R.layout.activity_display_novel_pager); UIHelper.SetActionBarDisplayHomeAsUp(this, true); setContentView(R.layout.activity_display_novel_pager); } else { UIHelper.SetTheme(this, R.layout.activity_display_novel_pager_fix); UIHelper.SetActionBarDisplayHomeAsUp(this, true); setContentView(R.layout.activity_display_novel_pager_fix); } tabHost = (TabHost) findViewById(android.R.id.tabhost); lam = new LocalActivityManager(this, false); lam.dispatchCreate(savedInstanceState); tabHost.setup(lam); isInverted = UIHelper.getColorPreferences(this); tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() { public void onTabChanged(String tabId) { setTabColor(); currentActivity = lam.getActivity(tabId); } }); /* Dynamically add Tabs */ ArrayList<String> Choice = new ArrayList<String>(); Iterator<Entry<String, AlternativeLanguageInfo>> it = AlternativeLanguageInfo.getAlternativeLanguageInfo().entrySet().iterator(); while (it.hasNext()) { AlternativeLanguageInfo info = it.next().getValue(); boolean isChosen = PreferenceManager.getDefaultSharedPreferences(this).getBoolean(info.getLanguage(), true); if (isChosen) { Choice.add(info.getLanguage()); Log.d("Language Added: ", info.getLanguage()); } it.remove(); } TabSpec[] allSpec = new TabSpec[Choice.size()]; for (int i = 0; i < Choice.size(); i++) { allSpec[i] = tabHost.newTabSpec(Choice.get(i)); allSpec[i].setIndicator(Choice.get(i)); Intent firstIntent = new Intent(this, DisplayAlternativeNovelListActivity.class); firstIntent.putExtra("LANG", Choice.get(i)); allSpec[i].setContent(firstIntent); // Adding all TabSpec to TabHost tabHost.addTab(allSpec[i]); // Cheap preload list hack. tabHost.setCurrentTabByTag(Choice.get(i)); } // Tab color setTabColor(); }
Example 18
Source File: AbstractCommentFragment.java From Plumble with GNU General Public License v3.0 | 4 votes |
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { LayoutInflater inflater = LayoutInflater.from(getActivity()); View view = inflater.inflate(R.layout.dialog_comment, null, false); mCommentView = (WebView) view.findViewById(R.id.comment_view); mCommentEdit = (EditText) view.findViewById(R.id.comment_edit); mTabHost = (TabHost) view.findViewById(R.id.comment_tabhost); mTabHost.setup(); if(mComment == null) { mCommentView.loadData("Loading...", null, null); requestComment(mProvider.getService()); } else { loadComment(mComment); } TabHost.TabSpec viewTab = mTabHost.newTabSpec("View"); viewTab.setIndicator(getString(R.string.comment_view)); viewTab.setContent(R.id.comment_tab_view); TabHost.TabSpec editTab = mTabHost.newTabSpec("Edit"); editTab.setIndicator(getString(isEditing() ? R.string.comment_edit_source : R.string.comment_view_source)); editTab.setContent(R.id.comment_tab_edit); mTabHost.addTab(viewTab); mTabHost.addTab(editTab); mTabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() { @Override public void onTabChanged(String tabId) { if("View".equals(tabId)) { // When switching back to view tab, update with user's HTML changes. mCommentView.loadData(mCommentEdit.getText().toString(), "text/html", "UTF-8"); } else if("Edit".equals(tabId) && "".equals(mCommentEdit.getText().toString())) { // Load edittext content for the first time when the tab is selected, to improve performance with long messages. mCommentEdit.setText(mComment); } } }); mTabHost.setCurrentTab(isEditing() ? 1 : 0); AlertDialog.Builder adb = new AlertDialog.Builder(getActivity()); adb.setView(view); if (isEditing()) { adb.setPositiveButton(R.string.save, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { editComment(mProvider.getService(), mCommentEdit.getText().toString()); } }); } adb.setNegativeButton(R.string.close, null); return adb.create(); }
Example 19
Source File: DrMIPSActivity.java From drmips with GNU General Public License v3.0 | 4 votes |
/** * Creates/places the tabs in the Tabhost. */ private void createTabs() { tabHost = (TabHost)findViewById(android.R.id.tabhost); tabHost.setup(); TabSpec tabCode = tabHost.newTabSpec("tabCode"); tabCode.setIndicator(getString(R.string.code)); tabCode.setContent(R.id.tabCode); tabHost.addTab(tabCode); txtCode = (EditText)findViewById(R.id.txtCode); lblFilename = (TextView)findViewById(R.id.lblFilename); txtCode.addTextChangedListener(new CodeEditorTextWatcher()); TabSpec tabAssembledCode = tabHost.newTabSpec("tabAssembledCode"); tabAssembledCode.setIndicator(getString(R.string.assembled)); tabAssembledCode.setContent(R.id.tabAssembledCode); tabHost.addTab(tabAssembledCode); tblAssembledCode = (TableLayout)findViewById(R.id.tblAssembledCode); cmbAssembledCodeFormat = (Spinner)findViewById(R.id.cmbAssembledCodeFormat); cmbAssembledCodeFormat.setOnItemSelectedListener(spinnersListener); cmbAssembledCodeFormat.setSelection(DrMIPS.getApplication().getPreferences().getInt(DrMIPS.ASSEMBLED_CODE_FORMAT_PREF, DrMIPS.DEFAULT_ASSEMBLED_CODE_FORMAT)); TabSpec tabDatapath = tabHost.newTabSpec("tabDatapath"); tabDatapath.setIndicator(getString(R.string.datapath)); tabDatapath.setContent(R.id.tabDatapath); tabHost.addTab(tabDatapath); lblCPUFilename = (TextView)findViewById(R.id.lblCPUFilename); cmdStep = (ImageButton)findViewById(R.id.cmdStep); datapathScroll = (HorizontalScrollView)findViewById(R.id.datapathScroll); boolean performanceMode = DrMIPS.getApplication().getPreferences().getBoolean(DrMIPS.PERFORMANCE_MODE_PREF, DrMIPS.DEFAULT_PERFORMANCE_MODE); lblDatapathFormat = (TextView)findViewById(R.id.lblDatapathFormat); cmbDatapathFormat = (Spinner)findViewById(R.id.cmbDatapathFormat); cmbDatapathFormat.setOnItemSelectedListener(spinnersListener); cmbDatapathFormat.setSelection(DrMIPS.getApplication().getPreferences().getInt(DrMIPS.DATAPATH_DATA_FORMAT_PREF, DrMIPS.DEFAULT_DATAPATH_DATA_FORMAT)); lblDatapathFormat.setVisibility(performanceMode ? View.GONE : View.VISIBLE); cmbDatapathFormat.setVisibility(performanceMode ? View.GONE : View.VISIBLE); lblDatapathPerformance = (TextView)findViewById(R.id.lblDatapathPerformance); cmbDatapathPerformance = (Spinner)findViewById(R.id.cmbDatapathPerformance); cmbDatapathPerformance.setOnItemSelectedListener(spinnersListener); cmbDatapathPerformance.setSelection(DrMIPS.getApplication().getPreferences().getInt(DrMIPS.PERFORMANCE_TYPE_PREF, DrMIPS.DEFAULT_PERFORMANCE_TYPE)); lblDatapathPerformance.setVisibility(!performanceMode ? View.GONE : View.VISIBLE); cmbDatapathPerformance.setVisibility(!performanceMode ? View.GONE : View.VISIBLE); tblExec = (TableLayout)findViewById(R.id.tblExec); tblExecRow = (TableRow)findViewById(R.id.tblExecRow); TabSpec tabRegisters = tabHost.newTabSpec("tabRegisters"); tabRegisters.setIndicator(getString(R.string.registers)); tabRegisters.setContent(R.id.tabRegisters); tabHost.addTab(tabRegisters); tblRegisters = (TableLayout)findViewById(R.id.tblRegisters); cmbRegistersFormat = (Spinner)findViewById(R.id.cmbRegistersFormat); cmbRegistersFormat.setOnItemSelectedListener(spinnersListener); cmbRegistersFormat.setSelection(DrMIPS.getApplication().getPreferences().getInt(DrMIPS.REGISTER_FORMAT_PREF, DrMIPS.DEFAULT_REGISTER_FORMAT)); TabSpec tabDataMemory = tabHost.newTabSpec("tabDataMemory"); tabDataMemory.setIndicator(getString(R.string.data_memory)); tabDataMemory.setContent(R.id.tabDataMemory); tabHost.addTab(tabDataMemory); tblDataMemory = (TableLayout)findViewById(R.id.tblDataMemory); cmbDataMemoryFormat = (Spinner)findViewById(R.id.cmbDataMemoryFormat); cmbDataMemoryFormat.setOnItemSelectedListener(spinnersListener); cmbDataMemoryFormat.setSelection(DrMIPS.getApplication().getPreferences().getInt(DrMIPS.DATA_MEMORY_FORMAT_PREF, DrMIPS.DEFAULT_DATA_MEMORY_FORMAT)); }
Example 20
Source File: SlideTabsActivity.java From GPS2SMS with GNU General Public License v3.0 | 4 votes |
private static void AddTab(SlideTabsActivity activity, TabHost tabHost, TabHost.TabSpec tabSpec) { tabSpec.setContent(new SlideTabsFactory(activity)); tabHost.addTab(tabSpec); }