布局总共有两种方法,第一种就是xml布局,还有就是自定义布局

                                                                                                                                                                                                                                                                
Activity是

package cc.tabhost;import android.app.Activity;import android.os.Bundle;import android.view.Menu;import android.view.View;import android.widget.TabHost;import android.widget.TabHost.TabSpec;import android.widget.TextView;public class MainActivity extends Activity {private TabHost tabhost;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);tabhost = (TabHost) this.findViewById(R.id.tabhost);tabhost.setup();// 首先找到tabwidget与TabContent两个控件TabSpec tabSpec = tabhost.newTabSpec("page1");// 设置标记。以后可以通过该标记找到该页tabSpec.setIndicator("首页", getResources().getDrawable(R.drawable.i1));// 设置显示的字,与图片// tabSpec.setIndicator(createTabview("首页"));//自定义布局用的tabSpec.setIndicator(View// v)tabSpec.setContent(R.id.page1);tabhost.addTab(tabSpec);tabSpec = tabhost.newTabSpec("page2");tabSpec.setIndicator("第二页", getResources().getDrawable(R.drawable.i2));// tabSpec.setIndicator(createTabview("第二页"));tabSpec.setContent(R.id.page2);tabhost.addTab(tabSpec);tabSpec = tabhost.newTabSpec("page3");tabSpec.setIndicator("第三页", getResources().getDrawable(R.drawable.i3));// tabSpec.setIndicator(createTabview("第三页"));//自定义tabcontent布局tabSpec.setContent(R.id.page3);tabhost.addTab(tabSpec);tabhost.setCurrentTab(0);// 选择停留到第一个页为首页}/** * 自定义布局, *  * @param 显示的首页 *            ,第二页。。 * @return 一个view */private View createTabview(String string) {View v = getLayoutInflater().inflate(R.layout.tab, null);// 找到自定义的tab布局TextView tv = (TextView) (v.findViewById(R.id.name));tv.setText(string);return v;}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.main, menu);return true;}}
以上有自定义布局与xml两种方法的代码,以下是自定义布句的tab.xml

<?xml version="1.0" encoding="utf-8"?>    





更多相关文章

  1. Android(安卓)快速使用 string.xml 中的array标签
  2. Android(安卓)图片左上角、右上角标签tag
  3. Android的setTag
  4. Android(安卓)如何删除短信
  5. xml解析(一) XmlPullParser的使用
  6. TabHost自定义标签页(一)
  7. 【MarsChen】D03_Say_Hello_to_Android
  8. Android之selector标签
  9. Android(安卓)Studio学习之对文件的基本了解

随机推荐

  1. PHP实例演示分支与循环
  2. PHP基础 -(一)变量、函数、参数
  3. 分支与循环、php模板语法与html混编技巧
  4. PHP:1. 实例演示分支与循环 2. 实例演示ph
  5. Android(安卓)调用WCF实例详解
  6. android的指纹问题
  7. 游戏开发4_01 数据存储--io
  8. Android(安卓)利用TransitionDrawable 实
  9. Android创建和删除桌面快捷方式
  10. 【总结备用】Android(安卓)获取正在运行