Refine search
public class MainActivity extends TabActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //setContentView(R.layout.activity_main); TabHost mTabHost = getTabHost(); mTabHost.addTab(mTabHost.newTabSpec("first").setIndicator("First").setContent(new Intent(this ,FirstActivity.class ))); mTabHost.addTab(mTabHost.newTabSpec("second").setIndicator("Second").setContent(new Intent(this , SecondActivity.class ))); mTabHost.setCurrentTab(0); } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.tabhost_container); TabHost tabs = (TabHost)this.findViewById(R.id.tabhost); tabs.setup(); tabs.addTab(tabs.newTabSpec("one").setContent(R.id.tab1content).setIndicator("TAB 1")); tabs.addTab(tabs.newTabSpec("two").setContent(R.id.tab2content).setIndicator("TAB 2")); tabs.setCurrentTab(0); } }
import android.app.Activity; import android.os.Bundle; import android.widget.TabHost; public class tabexample extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TabHost tabs = (TabHost)findViewById(R.id.TabHost01); tabs.setup(); TabHost.TabSpec spec1 = tabs.newTabSpec("tag1"); spec1.setContent(R.id.AnalogClock01); spec1.setIndicator("Analog Clock"); tabs.addTab(spec1); TabHost.TabSpec spec2 = tabs.newTabSpec("tag2"); spec2.setContent(R.id.DigitalClock01); spec2.setIndicator("Digital Clock"); tabs.addTab(spec2); } }
TabHost tabHost = getTabHost(); tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("Page1").setContent( new Intent(this, Page1.class))); tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("Page2").setContent( new Intent(this, Page2.class))); tabHost.addTab(tabHost.newTabSpec("tab3").setIndicator("Page3").setContent( new Intent(this, Page3.class)));
@Test public void shouldGetAndSetTheIntentContent() throws Exception { TabHost.TabSpec spec = new TabHost(context).newTabSpec("foo"); Intent intent = new Intent(); TabHost.TabSpec self = spec.setContent(intent); assertThat(self).isSameAs(spec); assertThat(shadowOf(spec).getContentAsIntent()).isSameAs(intent); }
@Test public void canGetCurrentTabTag() throws Exception { TabHost tabHost = new TabHost(context); TabHost.TabSpec foo = tabHost.newTabSpec("Foo"); TabHost.TabSpec bar = tabHost.newTabSpec("Bar"); TabHost.TabSpec baz = tabHost.newTabSpec("Baz"); tabHost.addTab(foo); tabHost.addTab(bar); tabHost.addTab(baz); tabHost.setCurrentTabByTag("Bar"); assertThat(tabHost.getCurrentTabTag()).isEqualTo("Bar"); }
TabHost tabHost = getTabHost(); TabSpec photospec = tabHost.newTabSpec("Photos"); photospec.setIndicator("Photos", getResources().getDrawable(R.drawable.icon1)); Intent photosIntent = new Intent(this, PhotosActivity.class); photospec.setContent(photosIntent); TabSpec videospec = tabHost.newTabSpec("Videos"); videospec.setIndicator("Videos", getResources().getDrawable(R.drawable.icon2)); Intent videosIntent = new Intent(this, VideosActivity.class); videospec.setContent(videosIntent); tabHost.addTab(photospec); tabHost.addTab(videospec);
public class YourProject extends TabActivity { @Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.main); Resources res = getResources(); TabHost tabHost = getTabHost(); tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("Tab1 title", res.getDrawable(R.drawable.logo1)).setContent(R.id.tab1Layout)); (...) //You can also fill tabs with a separate activity like so: Intent intent = new Intent(this, YourClass.class); tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("Another title", res.getDrawable(R.drawable.logo2)).setContent(intent)); tabHost.setCurrentTab(0); } }
TabHost tabHost = getTabHost(); Intent intent = new Intent().setClass(this, Overview.class); spec = tabHost.newTabSpec("overview") .setIndicator(Build.VERSION.SDK_INT < 11 ? this.getString(R.string.descr) : "", res.getDrawable(R.drawable.tab_overview)) .setContent(intent);
@Test public void shouldFireTheTabChangeListenerWhenCurrentTabIsSet() throws Exception { TabHost tabHost = new TabHost(context); TabHost.TabSpec foo = tabHost.newTabSpec("Foo"); TabHost.TabSpec bar = tabHost.newTabSpec("Bar"); TabHost.TabSpec baz = tabHost.newTabSpec("Baz"); tabHost.addTab(foo); tabHost.addTab(bar); tabHost.addTab(baz); TestOnTabChangeListener listener = new TestOnTabChangeListener(); tabHost.setOnTabChangedListener(listener); tabHost.setCurrentTab(2); assertThat(listener.tag).isEqualTo("Baz"); }
@Test public void shouldFireTheTabChangeListenerWhenTheCurrentTabIsSetByTag() throws Exception { TabHost tabHost = new TabHost(context); TabHost.TabSpec foo = tabHost.newTabSpec("Foo"); TabHost.TabSpec bar = tabHost.newTabSpec("Bar"); TabHost.TabSpec baz = tabHost.newTabSpec("Baz"); tabHost.addTab(foo); tabHost.addTab(bar); tabHost.addTab(baz); TestOnTabChangeListener listener = new TestOnTabChangeListener(); tabHost.setOnTabChangedListener(listener); tabHost.setCurrentTabByTag("Bar"); assertThat(listener.tag).isEqualTo("Bar"); }
@Override public void onCreate(Bundle state) { super.onCreate(state); setContentView(R.layout.main); TabHost tabs=(TabHost)findViewById(R.id.tabhost); tabs.setup(); TabHost.TabSpec spec=tabs.newTabSpec("tag1"); spec.setContent(R.id.tab1); spec.setIndicator("Clock"); tabs.addTab(spec); spec=tabs.newTabSpec("tag2"); spec.setContent(R.id.tab2); spec.setIndicator("Button"); tabs.addTab(spec); } }
TabHost tabHost = getTabHost(); // The activity TabHost TabHost.TabSpec spec; // Reusable TabSpec for each tab Intent intent; // Reusable Intent for each tab // Create an Intent to launch an Activity for the Movies tab. intent = new Intent().setClass(this, BarActivity.class); // Initialise a TabSpec for the Movies tab and add it to the TabHost. spec = tabHost.newTabSpec("Nights").setIndicator("Nights").setContent(intent); tabHost.addTab(spec); // Do the same things for the Theatres tab. intent = new Intent().setClass(this, BarActivity.class); spec = tabHost.newTabSpec("Weeks").setIndicator("Weeks").setContent(intent); tabHost.addTab(spec);
intent = new Intent().setClass(this, FirstGroupActivity.class); spec = tabHost.newTabSpec("first").setIndicator("First").setContent(intent); tabHost.addTab(spec); intent = new Intent().setClass(this, SecondGroupActivity.class); spec = tabHost.newTabSpec("second").setIndicator("Second").setContent(intent); tabHost.addTab(spec); intent = new Intent().setClass(this, ThirdGroupActivity.class); spec = tabHost.newTabSpec("third").setIndicator("Third").setContent(intent); tabHost.addTab(spec); intent = new Intent().setClass(this, ForthActivity.class); spec = tabHost.newTabSpec("forth").setIndicator("Forth").setContent(intent); tabHost.addTab(spec); tabHost.setCurrentTab(0); tabHost.setCurrentTab(0); firstButton.setBackgroundResource(R.drawable.btn_first_on); secondButton.setBackgroundResource(R.drawable.btn_second_off); tabHost.setCurrentTab(1); firstButton.setBackgroundResource(R.drawable.btn_first_off); secondButton.setBackgroundResource(R.drawable.btn_second_on);
TabHost.TabSpec spec = mTabHost.newTabSpec(AppConstants.TAB_A); mTabHost.setCurrentTab(-3); spec.setContent(new TabHost.TabContentFactory() { public View createTabContent(String tag) { mTabHost.addTab(spec); spec = mTabHost.newTabSpec(AppConstants.TAB_B); spec.setContent(new TabHost.TabContentFactory() { public View createTabContent(String tag) { mTabHost.addTab(spec); mTabHost.setCurrentTab(val);
@Test public void setCurrentTabByTagShouldAcceptNullAsParameter() throws Exception { TabHost tabHost = new TabHost(context); TabHost.TabSpec foo = tabHost.newTabSpec("Foo"); tabHost.addTab(foo); tabHost.setCurrentTabByTag(null); assertThat(tabHost.getCurrentTabTag()).isEqualTo("Foo"); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.tabhost_container); tabHost = (TabHost)this.findViewById(R.id.tabhost); tabHost.setup(); tabHost.addTab(tabHost.newTabSpec("one").setContent(R.id.tab1content).setIndicator("TAB 1")); tabHost.addTab(tabHost.newTabSpec("two").setContent(R.id.tab2content).setIndicator("TAB 2")); tabHost.findViewById(R.id.tab1button).setOnClickListener(goToTab2()); tabHost.findViewById(R.id.tab2button).setOnClickListener(goToTab1()); }
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, ArtistsActivity.class); // Initialize a TabSpec for each tab and add it to the TabHost spec = tabHost.newTabSpec("artists").setIndicator("Artists", res.getDrawable(R.drawable.ic_tab_artists)) .setContent(intent); tabHost.addTab(spec);
Display display = getWindowManager().getDefaultDisplay(); int width = display.getWidth(); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); TabHost mTabHost = getTabHost(); mTabHost.addTab(mTabHost.newTabSpec("tab_test1") .setIndicator((""),getResources().getDrawable(R.drawable.mzl_05)) .setContent(new Intent(this, NearBy.class))); mTabHost.addTab(mTabHost.newTabSpec("tab_test2") .setIndicator((""),getResources().getDrawable(R.drawable.mzl_08)) .setContent(new Intent(this, SearchBy.class))); mTabHost.setCurrentTab(0); mTabHost.getTabWidget().getChildAt(0).setLayoutParams(new LinearLayout.LayoutParams((width/2)-2,50)); mTabHost.getTabWidget().getChildAt(1).setLayoutParams(new LinearLayout.LayoutParams((width/2)-2,50));
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TabHost mTabHost = getTabHost(); mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("Tab 1").setContent(R.id.textview1)); mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator("Tab 2").setContent(R.id.textview2)); mTabHost.addTab(mTabHost.newTabSpec("tab_test3").setIndicator("Tab 3").setContent(R.id.textview3)); mTabHost.setCurrentTab(0); }