红色的是res下drawable文件夹下的一个selector文件,内容是
Selector文件代码

<?xml version="1.0" encoding="UTF-8"?> <selector   xmlns:android="[url=http://schemas.android.com/apk/res/android]http://schemas.android.com/apk/res/android[/url]">     <item android:state_focused="false" android:state_selected="false" android:state_pressed="false" android:drawable=<span style="background-color: #00ff00;">"@drawable/tab_timeline_normal" /></span>     <item android:state_focused="false" android:state_selected="true" android:state_pressed="false" android:drawable=<span style="background-color: #00ff00;">"@drawable/tab_timeline_active" /></span>     <item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable=<span style="background-color: #00ff00;">"@drawable/tab_timeline_normal" /></span>    <item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:drawable=<span style="background-color: #00ff00;">"@drawable/tab_timeline_active" /></span>    <item android:state_pressed="true" android:drawable=<span style="background-color: #00ff00;">"@drawable/tab_timeline_normal" /></span> </selector>

也是你按下时,和不按时等有一个效果上的改变,具体的可以参看关于selector的知识。绿色的就是两张不同效果的图片

Mainactivity代码
public class MainActivity extends TabActivity {         private TabHost tabHost;        private RadioGroup mainbtGroup;        private static final String HOME = "主页";        private static final String REFER = "提及";        private static final String SECRET = "私信";        private static final String SEARCH = "搜索";        private static final String ATTENTIION = "关注";             @Override         public void onCreate(Bundle savedInstanceState) {                 super.onCreate(savedInstanceState);                 setContentView(R.layout.tabhost);               tabHost = this.getTabHost();               View view1 = View.inflate(MainActivity.this, R.layout.tab, null);                 ((ImageView) view1.findViewById(R.id.tab_imageview_icon)).setImageResource(<span style="background-color: #ff0000;">R.drawable.tab_timeline_selector)</span>;                 ((TextView) view1.findViewById(R.id.tab_textview_title)).setText(HOME);            TabHost.TabSpec spec1 = tabHost.newTabSpec(HOME)                                 .setIndicator(view1)                                 .setContent(new Intent(this, HomeTimeLineActivity.class));                 tabHost.addTab(spec1);                                View view2 = View.inflate(MainActivity.this, R.layout.tab, null);                 ((ImageView) view2.findViewById(R.id.tab_imageview_icon)).setImageResource(<span style="background-color: #ff0000;">R.drawable.tab_atme_selector)</span>;                ((TextView) view2.findViewById(R.id.tab_textview_title)).setText(REFER);                 TabHost.TabSpec spec2 = tabHost.newTabSpec(REFER)                                 .setIndicator(view2)                                 .setContent(new Intent(this, ReferActivity.class));                 tabHost.addTab(spec2);                                 View view3 = View.inflate(MainActivity.this, R.layout.tab, null);                ((ImageView) view3.findViewById(R.id.tab_imageview_icon)).setImageResource(<span style="background-color: #ff0000;">R.drawable.tab_message_selector)</span>;                 ((TextView) view3.findViewById(R.id.tab_textview_title)).setText(SECRET);             TabHost.TabSpec spec3 = tabHost.newTabSpec(SECRET)                                .setIndicator(view3)                               .setContent(new Intent(this, MessageActivity.class));                 tabHost.addTab(spec3);                                 View view4 = View.inflate(MainActivity.this, R.layout.tab, null);                ((ImageView) view4.findViewById(R.id.tab_imageview_icon)).setImageResource(<span style="background-color: #ff0000;">R.drawable.tab_explore_selector</span>);                 ((TextView) view4.findViewById(R.id.tab_textview_title)).setText(SEARCH);               TabHost.TabSpec spec4 = tabHost.newTabSpec(SEARCH)                               .setIndicator(view4)                               .setContent(new Intent(this, SearchActivity.class));                 tabHost.addTab(spec4);                                 View view5 = View.inflate(MainActivity.this, R.layout.tab, null);                 ((ImageView) view5.findViewById(R.id.tab_imageview_icon)).setImageResource(<span style="background-color: #ff0000;">R.drawable.tab_focus_selector</span>);                 ((TextView) view5.findViewById(R.id.tab_textview_title)).setText(ATTENTIION);              TabHost.TabSpec spec5 = tabHost.newTabSpec(ATTENTIION)                                 .setIndicator(view5)                               .setContent(new Intent(this, AttentionActivity.class));                 tabHost.addTab(spec5);         } 

是一张.9.png格式的图片,这个很有用哟在android里,经常用来处理图片拉升的问题。左边和上面的小点表示要拉伸的地方,右边和下面的表示内容区。关于.9.png格式图片在android里面得更多应用看<a href="http://developer.android.com/guide/developing/tools/draw9patch.html">这里</a>

Tabhost布局文件代码
<?xml version="1.0" encoding="UTF-8"?> <TabHost android:id="@android:id/tabhost"  
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="[url=http://schemas.android.com/apk/res/android]http://schemas.android.com/apk/res/android[/url]"> <RelativeLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent"
             android:layout_height="fill_parent" /> <TabWidget android:id="@android:id/tabs" <span style="background-color: #ff0000;">
              android:background="@drawable/tab_bkg"</span> android:fadingEdge="none" android:fadingEdgeLength="0.0px" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" /> </RelativeLayout> </TabHost>

Tabhost布局文件代码

android:layout_alignParentBottom="true" 把tab的五个按钮挨着父控件的底部,在android里面RelativeLayout很好用 

Tab布局文件,就是你看到的那5个按钮的布局文件代码

<?xml version="1.0" encoding="UTF-8"?> <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content"   xmlns:android="[url=http://schemas.android.com/apk/res/android]http://schemas.android.com/apk/res/android[/url]">     <ImageView android:id="@+id/tab_imageview_icon" android:layout_width="fill_parent" android:layout_height="32.0dip" android:scaleType="fitCenter" />     <TextView android:id="@+id/tab_textview_title" android:textSize="11.0sp"  android:ellipsize="marquee" android:gravity="center" android:layout_width="fill_parent" android:layout_height="wrap_content" android:singleLine="true" android:marqueeRepeatLimit="1" /> </LinearLayout> 

更多相关文章

  1. FragmentTabHost使用
  2. Android(安卓)Widget 中ListView加载网络图片
  3. Android(安卓)DownloadManager下载进度查询(系列3)
  4. android tips:从资源文件中读取文件流显示
  5. 清单文件,测试,打电话和发短信应用
  6. android之动画(一)通过AnimationDrawable控制逐帧动画
  7. Android(安卓)入门 和 环境搭建
  8. Android根据 uri 获得文件真实路径
  9. NPM 和webpack 的基础使用

随机推荐

  1. android AVD 4.0 下解决中文输入问题
  2. Android(安卓)service与Thread
  3. Andriod学习笔记(二)
  4. Android(安卓)实用技巧 --- 命令godir
  5. ANDROID自动化测试工具:ROBOTIUM
  6. Android(安卓)第三方开源SwipeToDismiss:
  7. Android(安卓)Studio自动生成带系统签名
  8. Android(安卓)Camera 使用小结
  9. Android(安卓)事件传递机制
  10. Android插件技术——(一)动态加载jar