Android TableHost 控件
2016-05-20 13:46
323 查看
刚开始实习,第一次接触到TabHost控件,在这里记录一下吧!
layout文件:
demo:http://download.csdn.net/detail/qq_31303013/9526256
layout文件:
<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="com.example.tablehostdemo.MainActivity"> <TabHost android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tabHost"> <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="50dp" android:background="@android:color/white" android:tabStripEnabled="false" android:divider="@android:color/transparent"> </TabWidget> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingTop="12dp"> </FrameLayout> </LinearLayout> </TabHost> </RelativeLayout>源代码:
public class MainActivity extends Activity { TabHost tabHost; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tabHost= (TabHost) findViewById(R.id.tabHost); getTabTitles(); } private void getTabTitles(){ tabHost.setup(); LayoutInflater inflater = LayoutInflater.from(MainActivity.this); for (int i=0; i<3; i++) { View tab = inflater.inflate(R.layout.topic_tab_spec, null); TextView txtTitle = (TextView) tab.findViewById(R.id.txtTitle); txtTitle.setText("Title" +i); TextView textView = new TextView(MainActivity.this); textView.setId(i+3); FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT); tabHost.getTabContentView().addView(textView, params); tabHost.addTab(tabHost.newTabSpec("Tab" + i).setIndicator(tab).setContent(textView.getId())); System.out.println("textView id:" + textView.getId()); getTopicList(textView,i); } } private void getTopicList(TextView textView,int code){ textView.setText("content"+code); } }
demo:http://download.csdn.net/detail/qq_31303013/9526256
相关文章推荐
- 十六进制颜色透明度
- android recovery模式
- 开发android的注意点
- Android图片压缩(质量压缩和尺寸压缩)
- Android Studio 做单元测试笔记
- AndroidStudio应用调试技巧(上)
- android图文居中按钮控件
- Android问题——PopupWindow的isShowing()一直都是返回false
- ionic actionsheet 在android下面目全非
- Android自定义View总结(一)基础知识与实例
- Android优秀资源整理合集(论菜鸟到高级攻城狮)
- 关于android中ListView的Adapter如何设计能通用的一些看法
- Android相关Demo
- android 日常迭代与维护总结一
- Android图片压缩
- Android 4.0 5.0 6.0特性
- 【android开发教程】环境搭建及HelloWorld
- 创建第一个Android 5.0应用程序
- Android 史上最简单的实现Canvas drawText文字垂直居中
- Android Monkey的用法