开发者

TabWidget activity

Is TabWidget. How to me under it to start Activity?

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.TabHost.TabContentFactory;
import android.widget.TabHost.TabSpec;

public class FileM extends Activity {

    private TabHost mTabHost;

    private void setupTabHost() {
        mTabHost = (TabHost) findViewById(androi开发者_开发百科d.R.id.tabhost);
        mTabHost.setup();
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.main);

        setupTabHost();
        mTabHost.getTabWidget().setDividerDrawable(R.drawable.tab_divider);

        setupTab(new TextView(this), "Система");
        setupTab(new TextView(this), "Удаление");
        setupTab(new TextView(this), "Бэкап");
    }

    private void setupTab(final View view, final String tag) {
        View tabview = createTabView(mTabHost.getContext(), tag);


        TabSpec setContent = mTabHost.newTabSpec(tag).setIndicator(tabview).setContent(new TabContentFactory() {
            public View createTabContent(String tag) {return view;}
        });
        mTabHost.addTab(setContent);

    }
    private static View createTabView(final Context context, final String text) {
        View view = LayoutInflater.from(context).inflate(R.layout.tabs_bg, null);
        TextView tv = (TextView) view.findViewById(R.id.tabsText);
        tv.setText(text);
        return view;
    }
}


Add the following code to start an activity under your tab...

 TabSpec ts1 = _tabHost.newTabSpec("Page1");
            Drawable a = getResources().getDrawable(R.drawable.icon);
            ts1.setIndicator("Test",a);
            ts1.setContent(new Intent(this,MyHome.class));
            _tabHost.addTab(ts1); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜