package com.example.tabdemo;
import android.app.TabActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class TabDemoActivity extends TabActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tab_demo);
TabHost tabHost=getTabHost();
LayoutInflater layoutInflater=LayoutInflater.from(this);
View view=layoutInflater.inflate(R.layout.activity_tab_demo, tabHost.getTabContentView(),true);
TabSpec spec1=tabHost.newTabSpec("tab1");
spec1.setIndicator("tab1");
spec1.setContent(R.id.view1);
tabHost.addTab(spec1);
TabSpec spec2=tabHost.newTabSpec("tab2");
spec2.setIndicator("tab2");
spec2.setContent(R.id.view2);
tabHost.addTab(spec2);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.tab_demo, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}