android之实现底部TabHost
2011-09-16 10:42
429 查看
先说布局文件,如下:利用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">
<AnalogClock
android: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
//标签切换处理,用setOnTabChangedListener
tabHost.setOnTabChangedListener(new OnTabChangeListener(){
public void onTabChanged(String tabId){
Toast.makeText(TabTestActivity.this, "This is a Test!", Toast.LENGTH_LONG).show();
}
});
}
}
说明:转载请注明出处!
<?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">
<AnalogClock
android: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
//标签切换处理,用setOnTabChangedListener
tabHost.setOnTabChangedListener(new OnTabChangeListener(){
public void onTabChanged(String tabId){
Toast.makeText(TabTestActivity.this, "This is a Test!", Toast.LENGTH_LONG).show();
}
});
}
}
说明:转载请注明出处!
相关文章推荐
- 【Android UI设计与开发】第08期:底部菜单栏(三)Fragment+FragmentTabHost实现仿新浪微博底部菜单栏
- Android TabHost +Fragment 实现底部菜单栏 .
- 【Android UI】FragmentTabHost 实现底部菜单
- Android (FragmentTabHost+RadioGroup)实现底部bar
- android之实现底部TabHost
- android底部选项卡(二)FragmentTabHost +Fragment 实现
- Android TabHost +Fragment 实现底部菜单栏
- Android ViewPager实现Tabhost选项卡底部滑块动态滑动过渡
- Android--FragmentTabHost+ViewPager+Fragment实现底部tab菜单栏
- Android开发Tabhost+RadioGroup实现底部菜单栏
- 【Android UI设计与开发】第08期:底部菜单栏(三)Fragment+FragmentTabHost实现仿新浪微博底部菜单栏
- Android 底部菜单的实现(TabHost)
- 【Android UI设计与开发】第08期:底部菜单栏(三)Fragment+FragmentTabHost实现仿新浪微博底部菜单栏
- Android博客挑错系列之一FragmentTabHost和ViewPager实现底部导航栏
- 【Android】底部菜单栏--Fragment+FragmentTabHost实现
- 【Android UI设计与开发】第08期:底部菜单栏(三)Fragment+FragmentTabHost实现仿新浪微博底部菜单栏
- Android典型界面设计——FragmentTabHost+Fragment实现底部tab切换
- 【Android UI设计与开发】第08期:底部菜单栏(三)Fragment+FragmentTabHost实现仿新浪微博底部菜单栏
- 【Android UI设计与开发】第08期:底部菜单栏(三)Fragment+FragmentTabHost实现仿新浪微博底部菜单栏
- Android工作学习第5天之TabHost实现菜单栏底部显示