Android开发之-tabHost-1
2016-04-22 00:00
357 查看
摘要: tabHost的使用方法1
1. 新建主界面
2.新建MainActivity
在这里tabHost的 id 是使用的自定义的 id 并且 MainActivity是继承的原生的Activity
setIndicator(button1) 使用自定义的 View 作为标签形式
setIndicator("标签2") 使用系统默认的tab标签形式 并设置文字为:”标签2“
下一章将说明第二种tabHost的使用方法。
1. 新建主界面
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <TabHost android:id="@+id/tabHost" android:layout_width="match_parent" android:layout_height="match_parent" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TabWidget android:id="@android:id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content" /> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="match_parent" android:layout_height="match_parent" > <!-- 第一个标签 --> <LinearLayout android:id="@+id/content1" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#ff0000" android:orientation="vertical" > </LinearLayout> <!-- 第二个标签 --> <LinearLayout android:id="@+id/content2" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#f0f000" android:orientation="vertical" > </LinearLayout> <!-- 第三个标签 --> <LinearLayout android:id="@+id/content3" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#0000ff" android:orientation="vertical" > </LinearLayout> </FrameLayout> </LinearLayout> </TabHost> </RelativeLayout>
2.新建MainActivity
import android.app.Activity; import android.os.Bundle; import android.widget.Button; import android.widget.TabHost; public class MainActivity extends Activity { private TabHost tabHost; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initViews(); } private void initViews() { Button button1 = new Button(this); button1.setText("标签1"); tabHost = (TabHost) findViewById(R.id.tabHost); tabHost.setup(); tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator(button1).setContent(R.id.content1)); tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("标签2").setContent(R.id.content2)); tabHost.addTab(tabHost.newTabSpec("tab3").setIndicator("标签3").setContent(R.id.content3)); } }
tabHost.newTabSpec("tab1") 里面参数是为了tabHost内部区别使用
在这里tabHost的 id 是使用的自定义的 id 并且 MainActivity是继承的原生的Activity
setIndicator(button1) 使用自定义的 View 作为标签形式
setIndicator("标签2") 使用系统默认的tab标签形式 并设置文字为:”标签2“
下一章将说明第二种tabHost的使用方法。
相关文章推荐
- android 选项卡(TabHost)如何放置在屏幕的底部
- Android入门之TabHost与TabWidget实例解析
- Android应用中使用TabHost组件继承TabActivity的布局方法
- android TabHost(选项卡)的使用方法
- 自定义RadioButton和ViewPager实现TabHost带滑动的页卡效果
- 详解Android应用中使用TabHost组件进行布局的基本方法
- android中TabHost的图标(48×48)和文字叠加解决方法
- Android控件之TabHost用法实例分析
- 实例讲解Android应用开发中TabHost的使用要点
- Android编程实现设置TabHost当中字体的方法
- Android程序开发之自定义设置TabHost,TabWidget样式
- 结合源码讲解Tabost
- Android TabHost详解
- Android的TabHost组件的功能和用法
- tabhost如何设置背景
- 关于自定义TabHost的使用和注意事项
- FragmentTabHost 使用;
- TabHost--使用Activity
- TabHost--ActivityGroup和TabActivity
- TabHost之心得