TabHost, ActivityGroup 的使用例子

TabHost的使用, 如果自定义的话 其实可以隐藏TabWidget 使用自己的Layout, 然后调用TabHost的方法来模拟点击Tab  mHost.setCurrentTabByTag("mblog_tab")

Ref: http://www.cnblogs.com/over140/archive/2011/03/02/1968042.html

如果在一个tab中需要支持还在一个界面启动Activity的话  那就需要ActivityGroup   具体可以看附件中的代码。


package com.javaeye.dengyin2000.android.jokes;

import android.app.ActivityGroup;
import android.os.Build;
import android.view.KeyEvent;
import android.view.View;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: EDENYIN
 * Date: 12/1/10
 * Time: 3:10 PM
 * To change this template use File | Settings | File Templates.
 */
public abstract class AbstractActivityGroup extends ActivityGroup {

    public List<View> viewHistory;

    public void replaceContentView(View view) {
        viewHistory.add(view);
        setContentView(view);
    }

    public void back() {
        if (!viewHistory.isEmpty()) {
            viewHistory.remove(viewHistory.get(viewHistory.size() - 1));
            if (viewHistory.isEmpty()) {
                finish();
                return;
            }
            setContentView(viewHistory.get(viewHistory.size() - 1));
        } else {
            finish();
        }
    }

    public void onBackPressed() {
        back();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {

        if (android.os.Build.VERSION.SDK_INT <= Build.VERSION_CODES.DONUT
                && keyCode == KeyEvent.KEYCODE_BACK
                && event.getRepeatCount() == 0) {
            // Take care of calling this method on earlier versions of
            // the platform where it doesn't exist.
            onBackPressed();
            return true;
        }

        return super.onKeyDown(keyCode, event);
    }
}

你可能感兴趣的:(android,layout,tabhost,tabwidget)