底部TabHost

自留备用

/**
 * <一句话功能简述>定制居底的TabHost
* <功能详细描述> * * @author chenli * @version [版本号, 2011-1-27] * @see [相关类/方法] * @since [产品/模块版本] */ public class MyTabHostFive extends TabActivity { /** * TabHost控件 */ private TabHost mTabHost; /** * TabWidget控件 */ private TabWidget mTabWidget; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mTabHost = this.getTabHost(); /* 去除标签下方的白线 */ mTabHost.setPadding(mTabHost.getPaddingLeft(), mTabHost.getPaddingTop(), mTabHost.getPaddingRight(), mTabHost.getPaddingBottom() - 5); Resources rs = getResources(); Intent layout1intent = new Intent(); layout1intent.setClass(this, Layout1.class); TabHost.TabSpec layout1spec = mTabHost.newTabSpec("layout1"); layout1spec.setIndicator("layou1", rs.getDrawable(android.R.drawable.stat_sys_phone_call)); layout1spec.setContent(layout1intent); mTabHost.addTab(layout1spec); Intent layout2intent = new Intent(); layout2intent.setClass(this, Layout2.class); TabHost.TabSpec layout2spec = mTabHost.newTabSpec("layout2"); layout2spec.setIndicator("layout2", rs.getDrawable(android.R.drawable.stat_sys_phone_call_forward)); layout2spec.setContent(layout2intent); mTabHost.addTab(layout2spec); Intent layout3intent = new Intent(); layout3intent.setClass(this, Layout3.class); TabHost.TabSpec layout3spec = mTabHost.newTabSpec("layout3"); layout3spec.setIndicator("layout3", rs.getDrawable(android.R.drawable.stat_sys_phone_call_on_hold)); layout3spec.setContent(layout3intent); mTabHost.addTab(layout3spec); /* 对Tab标签的定制 */ mTabWidget = mTabHost.getTabWidget(); for (int i = 0; i < mTabWidget.getChildCount(); i++) { /* 得到每个标签的视图 */ View view = mTabWidget.getChildAt(i); /* 设置每个标签的背景 */ if (mTabHost.getCurrentTab() == i) { view.setBackgroundDrawable(getResources().getDrawable( R.drawable.number_bg_pressed)); } else { view.setBackgroundDrawable(getResources().getDrawable( R.drawable.number_bg)); } /* 设置Tab间分割竖线的颜色 */ // tabWidget.setBackgroundColor(Color.WHITE); /* 设置Tab间分割竖线的背景图片 */ // tabWidget.setBackgroundResource(R.drawable.icon); /* 设置tab的高度 */ mTabWidget.getChildAt(i).getLayoutParams().height = 50; TextView tv = (TextView) mTabWidget.getChildAt(i).findViewById( android.R.id.title); /* 设置tab内字体的颜色 */ tv.setTextColor(Color.rgb(49, 116, 171)); } /* 当点击Tab选项卡的时候,更改当前Tab标签的背景 */ mTabHost.setOnTabChangedListener(new OnTabChangeListener() { @Override public void onTabChanged(String tabId) { for (int i = 0; i < mTabWidget.getChildCount(); i++) { View view = mTabWidget.getChildAt(i); if (mTabHost.getCurrentTab() == i) { view.setBackgroundDrawable(getResources().getDrawable( R.drawable.number_bg_pressed)); } else { view.setBackgroundDrawable(getResources().getDrawable( R.drawable.number_bg)); } } } }); } }



layout

package com.android.tabhost;

public class Layout2 extends Activity
{
    private TextView textView = null;

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout2);
        textView = (TextView) findViewById(R.id.text2);
        textView.setText("我是第二页!");
    }
}


main.xml



	
		
		
		

		
	


layout.xml



    




你可能感兴趣的:(android.ui)