Andorid TabActivity

实现分页式activity 效果图:

Andorid TabActivity

Andorid TabActivity


代码:

package com.example.tabhost;

import android.os.Bundle;
import android.app.ActionBar.Tab;
import android.app.Activity;
import android.app.TabActivity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.widget.TabHost;

@SuppressWarnings("deprecation")
//activity 继承自TabActivity
public class MainActivity extends TabActivity{

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //这里没有 setcontentview() 动态绑定布局
        TabHost mytab=getTabHost();//获取容器
        
        //过滤器
        LayoutInflater.from(this).inflate(R.layout.linerlayout, mytab.getTabContentView(),true);
        LayoutInflater.from(this).inflate(R.layout.relativelayout,mytab.getTabContentView(),true);
        //分页容器添加页面,为页面添加标签,还有布局
        mytab.addTab(mytab.newTabSpec("01").setIndicator("part 1").setContent(R.id.liner01));
        mytab.addTab(mytab.newTabSpec("02").setIndicator("part2").setContent(R.id.relativelayout01));
        
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
}

你可能感兴趣的:(Andorid TabActivity)