android activity tabhost
16lz
2021-12-04
在activity中使用tab
以下是java代码
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical" android:layout_width="fill_parent"android:layout_height="fill_parent"><TabHost android:id="@+id/tabhost" android:layout_width="fill_parent"android:layout_height="fill_parent"><TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="60px" android:paddingBottom="10dip" /> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="fill_parent" android:paddingTop="60px"> <TextView android:id="@+id/view1" android:background="@drawable/blue"android:layout_width="fill_parent" android:layout_height="fill_parent"android:text="@string/tabs_1_tab_1" /><TextView android:id="@+id/view2" android:background="@drawable/red"android:layout_width="fill_parent" android:layout_height="fill_parent"android:text="@string/tabs_1_tab_2" /></FrameLayout></TabHost></LinearLayout>
以下是java代码
@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.main);host=(TabHost) findViewById(R.id.tabhost);host.setup();//LayoutInflater.from(this).inflate(R.layout.main,//host.getTabContentView(), true);host.addTab(host.newTabSpec("1").setContent(R.id.view1).setIndicator("1"));host.addTab(host.newTabSpec("2").setContent(R.id.view2).setIndicator("2"));}
更多相关文章
- ?android:attr/属性 与 ?android:属性
- Android截取开机关机事件
- Android(安卓)防止启动页面(SplashActivity)被多次启动(笔记)
- Android(安卓)recyclerview实现查看更多/收起功能
- Android(安卓)设置图片倒影效果
- Android之使用ContentResolver对通信录中的数据进行简单操作
- android语音识别之科大讯飞语音API的使用
- android全屏代码
- Android(安卓)Activity 常用功能设置(全屏、横竖屏等)