Tab切换

这是一个唯一不需要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();
 }

 
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值