这是一个唯一不需要XML的,只需要代码的界面模式,当然,这个activity也必须要在AndroidManifest.xml中注册下才能调用:
package hello.me;
import android.app.TabActivity;
import android.app.AlertDialog.Builder;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.webkit.WebView;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
public class swmenu extends TabActivity {
WebView wv;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setTitle("Tab测试");
try{
TabHost tabHost = getTabHost();
LayoutInflater.from(this).inflate(R.layout.menua,tabHost.getTabContentView(), true);
tabHost.addTab(tabHost.newTabSpec("时报").setIndicator("时报",getResources().getDrawable(R.drawable.a1)).setContent(new Intent(this, WebTab.class)));
tabHost.addTab(tabHost.newTabSpec("日报").setIndicator("日报",getResources().getDrawable(R.drawable.sun)).setContent(new Intent(this, WebTab.class)));
tabHost.addTab(tabHost.newTabSpec("预警阀值").setIndicator("预警阀值",getResources().getDrawable(R.drawable.yj)).setContent(new Intent(this, WebTab.class)));
tabHost.addTab(tabHost.newTabSpec("L-V关系").setIndicator("L-V关系",getResources().getDrawable(R.drawable.report)).setContent(new Intent(this, WebTab.class)));
tabHost.setCurrentTab(0);
wv = (WebView) findViewById(R.id.wv1);
Const.urlhtml="http://" + Const.host +"/report/hsw.aspx";
wv.loadUrl(Const.urlhtml);
tabHost.setOnTabChangedListener(new OnTabChangeListener(){
@Override
public void onTabChanged(String tabId) {
// TODO Auto-generated method stub
//showInfo(tabId);
if(tabId=="时报")
Const.urlhtml="http://" + Const.host +"/report/hsw.aspx";
if(tabId=="日报")
Const.urlhtml="http://" + Const.host +"/report/sw.aspx";
if(tabId=="L-V关系")
Const.urlhtml="http://" + Const.host +"/report/sw_kr.aspx";
if(tabId=="预警阀值")
Const.urlhtml="http://" + Const.host +"/report/yjsw.aspx";
wv.loadUrl(Const.urlhtml);
}
});
}catch(Exception ex){
showInfo(ex.toString());
}
}
/**
* 当点击tab选项卡的时候,更改当前的背景
*/
public void showInfo(String str) {
Builder builder = new Builder(swmenu.this);
builder.setTitle("提示");
builder.setMessage(str);
builder.setCancelable(true);
builder.create().show();
}
}