您的位置:首页 > 其它

任务一:使用选项卡实现页面切换

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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: