选项卡(TabHost)
来源:互联网 发布:全国省市区sql 编辑:程序博客网 时间:2024/05/01 06:46
fragment_main.xml
<TabHost 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" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.xwy.Xuan.MainActivity$PlaceholderFragment" android:id="@android:id/tabhost" > <LinearLayout android:orientation="vertical" 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"/> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="fill_parent"></FrameLayout> </LinearLayout> </TabHost>
tab1.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/LinearLayout01" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="韩慧" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="韩1慧" /></LinearLayout>
tab2.xml
<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:id="@+id/FrameLayout02"> <LinearLayout android:id="@+id/LinearLayout02" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:text="暂无未接来电" android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LinearLayout></FrameLayout>
MainActivity.java
package com.xwy.Xuan;import android.support.v4.app.Fragment;import android.app.Activity;import android.os.Bundle;import android.view.LayoutInflater;import android.view.Menu;import android.view.MenuItem;import android.view.View;import android.view.ViewGroup;import android.widget.TabHost;public class MainActivity extends Activity {private TabHost tabHost;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.fragment_main);tabHost = (TabHost) findViewById(android.R.id.tabhost);tabHost.setup();LayoutInflater inflater = LayoutInflater.from(this);inflater.inflate(R.layout.tab1, tabHost.getTabContentView());inflater.inflate(R.layout.tab2, tabHost.getTabContentView());tabHost.addTab(tabHost.newTabSpec("tab01").setIndicator("未接来电").setContent(R.id.LinearLayout01));tabHost.addTab(tabHost.newTabSpec("tab02").setIndicator("以接来电").setContent(R.id.FrameLayout02));}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.main, menu);return true;}@Overridepublic boolean onOptionsItemSelected(MenuItem item) {// Handle action bar item clicks here. The action bar will// automatically handle clicks on the Home/Up button, so long// as you specify a parent activity in AndroidManifest.xml.int id = item.getItemId();if (id == R.id.action_settings) {return true;}return super.onOptionsItemSelected(item);}/** * A placeholder fragment containing a simple view. */public static class PlaceholderFragment extends Fragment {public PlaceholderFragment() {}@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {View rootView = inflater.inflate(R.layout.fragment_main, container,false);return rootView;}}}
0 0
- 选项卡(TabHost)
- UI组件:选项卡(TabHost)
- 选项卡TabHost
- [控件]TabHost选项卡
- 初识选项卡 TabHost
- 选项卡 TabHost
- TabHost...选项卡
- android 选项卡TabHost
- android 选项卡TabHost
- TabHost 选项卡
- TabHost--选项卡案例
- android 选项卡(TabHost) 置底
- android 底部选项卡(TabHost)
- Android TabHost选项卡编程
- 选项卡TabHost的使用
- android TabHost选项卡示例
- android中tabhost选项卡
- android tabHost选项卡自定义
- zclip 复制内容到剪切板
- mysql的相仿indexOf方法
- SWIFT学习笔记01
- 咦?这些产品当年都是怎么抢到第一批用户的?
- 更换程序里的字体,让程序变得更漂亮
- 选项卡(TabHost)
- 【VC】ChangeDisplaySettingsEx 设置显示器屏幕分辨率
- 创建验证码
- Laravel 第一个视图
- 深入研究PHP及Zend Engine的线程安全模型
- linux c++学习笔记0630
- 开源搜索引擎评估:lucene sphinx elasticsearch
- 怎么学习查找引擎优化技能?
- 一个重复滚动的轮子效果的动画