先说布局文件,如下:利用android:layout_alignParentBottom="true" 实现底部显示

<?xml version="1.0" encoding="utf-8"?><TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/tabhost"  android:orientation="vertical"    android:layout_width="fill_parent"    android:layout_height="fill_parent">    <RelativeLayout    android:background="@drawable/g"    android:layout_width="fill_parent"    android:layout_height="fill_parent">    <TabWidget android:id="@android:id/tabs"    android:layout_width="fill_parent"    android:layout_height="wrap_content"    android:layout_alignParentBottom="true"></TabWidget><FrameLayout android:id="@android:id/tabcontent"    android:layout_width="fill_parent"    android:layout_height="fill_parent">    <RelativeLayout android:id="@+id/tabFirst"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="vertical">    <AnalogClockandroid:id="@+id/widget31"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerInParent="true"></AnalogClock>    </RelativeLayout>>    <RelativeLayout android:id="@+id/tabSecond"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="vertical">    <DigitalClock    android:layout_centerInParent="true"    android:layout_width="wrap_content"    android:layout_height="wrap_content">    </DigitalClock>    </RelativeLayout></FrameLayout></RelativeLayout></TabHost>

下面是主程序代码,注释写的比较详细,这里就不在多解释了

package com.cloay;import android.app.TabActivity;import android.graphics.Color;import android.os.Bundle;import android.widget.TabHost;import android.widget.TabHost.OnTabChangeListener;import android.widget.Toast;public class TabTestActivity extends TabActivity {TabHost tabHost;    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);        //获取TabHost对象        tabHost = getTabHost();   //        tabHost.setup();//新建一个newTabSpec,设置标签和图标(setIndicator),设置内容(setContent)tabHost.addTab(tabHost.newTabSpec("Test one").setIndicator("",getResources().getDrawable(android.R.drawable.ic_menu_call)).setContent(R.id.tabFirst));tabHost.addTab(tabHost.newTabSpec("Test two").setIndicator("",getResources().getDrawable(android.R.drawable.ic_menu_camera)).setContent(R.id.tabSecond));//设置TabHost的背景颜色tabHost.setBackgroundColor(Color.argb(150,22,70,150));//设置TabHost的背景图片资源//tabHost.setBackgroundResource(R.drawable.bg);//设置当前现实哪一个标签tabHost.setCurrentTab(0);   //0为标签ID//标签切换处理,用setOnTabChangedListenertabHost.setOnTabChangedListener(new OnTabChangeListener(){public void onTabChanged(String tabId){Toast.makeText(TabTestActivity.this, "This is a Test!", Toast.LENGTH_LONG).show();}});    }}


说明:转载请注明出处!


更多相关文章

  1. mybatisplus的坑 insert标签insert into select无参数问题的解决
  2. Android之进度条
  3. Android(安卓)软键盘问题总结
  4. ExpandableListView设置选中child的背景
  5. Android中的AnimationDrawable的使用
  6. Android小问题解决办法记录
  7. Android(安卓)App 权限一点知识
  8. Android(安卓)小说阅读护眼模式
  9. Android(安卓)获取系统设置参数。

随机推荐

  1. Android权限说明
  2. android 启动socket 失败:socket(af_inet
  3. Android(安卓)自定义控件实现刮刮卡效果
  4. Android Intent传递对象和集合
  5. Android中invalidate()和postInvalidate(
  6. Android打开关闭触摸提示音
  7. Qt for Android(安卓)部署流程分析
  8. android Canvas清屏只需三句话
  9. 网上找了些Android数据库操作的代码
  10. Android ListView滑动时出现黑屏解决方法