使用TabHost实现顶部菜单栏
来源:互联网 发布:mac怎么设置壁纸 编辑:程序博客网 时间:2024/06/07 07:09
首先,分析下使用TabHost的布局。
最外层就是一个TabHost布局,上边为菜单布局,菜单下边为内容,使用线性布局实现。
菜单栏为一个TabWidget,要实现点击每个菜单,跳转不同的内容界面,所有内容布局中就需要使用
帧布局FrameLayout.
给出布局文件:
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/tabhost"> <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TabWidget android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@android:id/tabs" > </TabWidget> <FrameLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@android:id/tabcontent" > <LinearLayout android:id="@+id/page1" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="第一页" /> </LinearLayout> <LinearLayout android:id="@+id/page2" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="第二页" /> </LinearLayout> <LinearLayout android:id="@+id/page3" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="第三页" /> </LinearLayout> </FrameLayout> </LinearLayout></TabHost>
Activity:
package com.example.tabhost;import android.support.v7.app.ActionBarActivity;import android.os.Bundle;import android.view.Menu;import android.view.MenuItem;import android.widget.TabHost;import android.widget.TabHost.TabSpec;public class MainActivity extends ActionBarActivity {TabHost tabHost;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);tabHost = (TabHost) this.findViewById(R.id.tabhost);tabHost.setup();//一定要执行该方法,该方法是能够查找TabWidget和FrameLayoutTabSpec tabSpec = tabHost.newTabSpec("page1");//(通过帧布局实现)tabSpec.setIndicator("首页", getResources().getDrawable(R.drawable.i1));//设置标签题tabSpec.setContent(R.id.page1);//设置内容tabHost.addTab(tabSpec);tabSpec = tabHost.newTabSpec("page2");tabSpec.setIndicator("第二页", getResources().getDrawable(R.drawable.i2));//设置标签题tabSpec.setContent(R.id.page2);//设置内容tabHost.addTab(tabSpec);tabSpec = tabHost.newTabSpec("page3");tabSpec.setIndicator("第三页", getResources().getDrawable(R.drawable.i5));//设置标签题tabSpec.setContent(R.id.page3);//设置内容tabHost.addTab(tabSpec);tabHost.setCurrentTab(0);}}
代码链接:http://download.csdn.net/detail/tan313/8301961
0 0
- 使用TabHost实现顶部菜单栏
- 使用Fragment实现顶部菜单栏
- actionbar+tabhost菜单栏实现
- 使用TabHost实现类网易新闻-底部固定菜单栏
- 使用TabHost实现类网易新闻-底部固定菜单栏
- 底部菜单栏实现之TabHost
- Android使用TabLayout+ViewPager实现顶部滑动菜单栏
- Android TabHost +Fragment 实现底部菜单栏
- Android TabHost +Fragment 实现底部菜单栏 .
- Android开发Tabhost+RadioGroup实现底部菜单栏
- 史上最详细的TabHost菜单栏实现
- Android底部菜单栏(tabhost实现)
- 底部菜单栏(一) TabHost实现
- 顶部菜单栏。。。
- android仿微信顶部菜单栏的实现
- ViewPager+FragmentPagerAdapter+RadioGroup实现顶部菜单栏
- android tabhost底部菜单栏实现原理与代码
- 使用选项卡TabWidget与TabHost实现底部或者顶部四个分类按钮 点击切换对应的fragment
- 工作流书籍
- 正则表达式验证URL
- iOS开发自动释放池@autoreleasepool的使用注意事项以及ARC机制——面试必考内容
- GUI修改注意事项
- iOS开发之使用CocoaPods更新第三方出现“target overrides the `CLANG_CXX_LANGUAGE_STANDARD`……”问题解决方案
- 使用TabHost实现顶部菜单栏
- elasticsearch在有代理的情况下安装head plugin
- Unity Shader 基础知识(二)
- SpringMVC_使用
- 过热或过热或果然
- 32款 jQuery UI框架开源软件
- 删除tomcat7.0的server文件夹出错
- Android View scrollTo scrollBy
- imx6smart剪裁