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); } }
final TabHost tabHost = (TabHost) getTabHost(); tabHost.addTab(createTab(TopNewsActivity.class, "topNews", "Top News", R.drawable.tab_news)); tabHost.addTab(createTab(PowerActivity.class, "power", "Power", R.drawable.tab_power)); tabHost.addTab(createTab(EnergyActivity.class, "energy", "Renewable Energy", R.drawable.tab_energy)); tabHost.addTab(createTab(CoalActivity.class, "coal", "Coal", R.drawable.tab_coal)); tabHost.addTab(createTab(OilnGasActivity.class, "oilnGas", "Oil & Gas", R.drawable.tab_oilngas)); tabHost.setCurrentTab(0); tabHost.getTabWidget().getChildAt(0).getLayoutParams().width = 140; tabHost.getTabWidget().getChildAt(1).getLayoutParams().width = 140; final String title, final int drawable) final Intent intent = new Intent().setClass(this, intentClass);
TabHost tabHost = getTabHost(); // Tab for Photos TabSpec photospec = tabHost.newTabSpec("Photos"); // setting Title and Icon for the Tab photospec.setIndicator("Photos", getResources().getDrawable(R.drawable.icon_photos_tab)); Intent photosIntent = new Intent(this, PhotosActivity.class); photospec.setContent(photosIntent); // Adding all TabSpec to TabHost tabHost.addTab(photospec); // Adding photos tab tabHost.addTab(songspec); // Adding songs tab tabHost.addTab(videospec); // Adding videos tab
@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"); }
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)));
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); } }
@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(); 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);
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); }
@Test public void shouldRetrieveTheCurrentViewFromTabContentFactory() { TabHost tabHost = new TabHost(context); TabHost.TabSpec foo = tabHost .newTabSpec("Foo") .setContent( tag -> { TextView tv = new TextView(context); tv.setText("The Text of " + tag); return tv; }); tabHost.addTab(foo); tabHost.setCurrentTabByTag("Foo"); TextView textView = (TextView) tabHost.getCurrentView(); assertThat(textView.getText().toString()).isEqualTo("The Text of Foo"); } @Test