任务一:使用选项卡实现页面切换
2014-04-26 21:05
295 查看
【程序截屏】
一、
二、
三、
四、
一、
package com.example.ui_task1.activity; import android.app.TabActivity; import android.graphics.Color; import android.os.Bundle; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.TabHost; public class MainActivity extends TabActivity { TabHost mTabHost; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mTabHost = getTabHost(); mTabHost.addTab(mTabHost .newTabSpec("tab_text1") .setIndicator("TAB 1", getResources().getDrawable(R.drawable.a)) .setContent(R.id.text1)); mTabHost.addTab(mTabHost .newTabSpec("tab_text1") .setIndicator("TAB 2", getResources().getDrawable(R.drawable.b)) .setContent(R.id.text2)); mTabHost.addTab(mTabHost .newTabSpec("tab_text1") .setIndicator("TAB 3", getResources().getDrawable(R.drawable.c)) .setContent(R.id.text3)); mTabHost.setBackgroundColor(Color.argb(150, 22, 70, 150)); //mTabHost.setBackgroundResource(R.drawable.t3); mTabHost.setCurrentTab(0); mTabHost.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub } } ); } public 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; } }
二、
/* AUTO-GENERATED FILE. DO NOT MODIFY. * * This class was automatically generated by the * aapt tool from the resource data it found. It * should not be modified by hand. */ package com.example.ui_task1.activity; public final class R { public static final class attr { } public static final class dimen { /** Default screen margins, per the Android Design guidelines. Customize dimensions originally defined in res/values/dimens.xml (such as screen margins) for sw720dp devices (e.g. 10" tablets) in landscape here. */ public static final int activity_horizontal_margin=0x7f040000; public static final int activity_vertical_margin=0x7f040001; } public static final class drawable { public static final int a=0x7f020000; public static final int b=0x7f020001; public static final int c=0x7f020002; public static final int ic_launcher=0x7f020003; public static final int t3=0x7f020004; public static final int to=0x7f020005; public static final int tt=0x7f020006; } public static final class id { public static final int action_settings=0x7f080003; public static final int text1=0x7f080000; public static final int text2=0x7f080001; public static final int text3=0x7f080002; } public static final class layout { public static final int activity_main=0x7f030000; } public static final class menu { public static final int main=0x7f070000; } public static final class string { public static final int action_settings=0x7f050001; public static final int app_name=0x7f050000; public static final int hello_world=0x7f050002; } public static final class style { /** Base application theme, dependent on API level. This theme is replaced by AppBaseTheme from res/values-vXX/styles.xml on newer devices. Theme customizations available in newer API levels can go in res/values-vXX/styles.xml, while customizations related to backward-compatibility can go here. Base application theme for API 11+. This theme completely replaces AppBaseTheme from res/values/styles.xml on API 11+ devices. API 11 theme customizations can go here. Base application theme for API 14+. This theme completely replaces AppBaseTheme from BOTH res/values/styles.xml and res/values-v11/styles.xml on API 14+ devices. API 14 theme customizations can go here. */ public static final int AppBaseTheme=0x7f060000; /** Application theme. All customizations that are NOT specific to a particular API-level can go here. */ public static final int AppTheme=0x7f060001; } }
三、
/** Automatically generated file. DO NOT MODIFY */ package com.example.ui_task1.activity; public final class BuildConfig { public final static boolean DEBUG = true; }
四、
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@android:id/tabhost" > <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingLeft="1dip" android:paddingRight="1dip" android:paddingTop="3dip" /> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="1dip" android:layout_weight="1" > <TextView android:id="@+id/text1" android:layout_height="fill_parent" android:layout_width="fill_parent" android:text="第一张"/> <TextView android:id="@+id/text2" android:layout_height="fill_parent" android:layout_width="fill_parent" android:text="第二张"/> <TextView android:id="@+id/text3" android:layout_height="fill_parent" android:layout_width="fill_parent" android:text="第三张"/> </FrameLayout> </LinearLayout> </TabHost>
相关文章推荐
- Android中使用ViewPager实现屏幕页面切换和页面切换效果
- 使用FragmentPagerAdapter实现页面切换速度很慢的问题,求高人解答
- 使用BottomTabBar实现类似Fragment页面切换
- jQuery实现切换页面布局使用介绍
- CSS+JS实现同一页面可以重复使用的选项卡
- [Android]使用PagerSlidingTabStrip来实现选项卡切换界面的示例
- 使用 pjax 实现无刷新切换页面
- 微信小程序开发之实现选项卡(窗口顶部TabBar)页面切换
- Android程序——使用选项卡实现界面切换
- 使用AngularJS实现可伸缩的页面切换的方法
- 使用AngularJS实现可伸缩的页面切换的方法
- 使用ViewPager+Fragment实现选项卡切换效果
- Windows Phone使用sliverlight toolkit实现页面切换动画效果
- 点击选项卡后页面标题切换的实现
- 使用TabHost和ViewPager实现页面切换
- Android成长日记-使用PagerAdapter实现页面切换
- 使用jQuery.animate实现简单的页面切换效果
- 使用ViewPager+Fragment实现选项卡切换效果
- Android 中使用 ViewPager实现屏幕页面切换和页面轮播效果
- Android中使用ViewFlipper实现屏幕页面切换(关于坐标轴的问题已补充更改)