TabWidget
16lz
2021-01-25
Android TabWidget/TabHost有两种使用方法:
第一种:使用系统自带写好的TabHost(及继承自TabActivity类)
第二种:就是定义我们自己的tabHost:不用继承TabActivity
这里我们使用第二章自定义tabHost的方法实现
示例:
main.xml
Activity.java
第一种:使用系统自带写好的TabHost(及继承自TabActivity类)
第二种:就是定义我们自己的tabHost:不用继承TabActivity
这里我们使用第二章自定义tabHost的方法实现
示例:
main.xml
<?xml version="1.0" encoding="utf-8"?><TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent" > <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="5dip"> <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" android:padding="5dip"> </FrameLayout> </LinearLayout></TabHost>
Activity.java
public class MainActivity extends TabActivity{@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);this.setContentView(R.layout.main);TabHost tabHost=this.getTabHost();Intent remoteIntent=new Intent();remoteIntent.setClass(this, mp3player.class);//内部类的写法,TabSpec代表一页的内容TabHost.TabSpec remoteSpec=tabHost.newTabSpec("remote");//使用android内部的图标,也可以使用自行下载的图片 代表了一页Resources res=this.getResources();remoteSpec.setIndicator("remote", res.getDrawable(android.R.drawable.arrow_down_float));remoteSpec.setContent(remoteIntent);tabHost.addTab(remoteSpec);Intent localIntent=new Intent();localIntent.setClass(this, LocalActivity.class);TabHost.TabSpec localSpec=tabHost.newTabSpec("local");localSpec.setIndicator("local", res.getDrawable(android.R.drawable.arrow_down_float));localSpec.setContent(localIntent);tabHost.addTab(localSpec);}}
更多相关文章
- android 不透明度16进制值
- Android(安卓)给Animation设置setRepeatMode不起作用
- Android(安卓)selector 的shape、gradient、stroke、corners 、s
- Android(安卓)MediaPlayer Error/Info Code
- android开发:activity继承AppCompatActivity 去掉标题栏
- 从头学Android之多媒体--使用MediaRecorder录制音频
- java 非静态内部类为什么持有外部类的引用
- 【Android(安卓)开发教程】注册事件监听器
- android 开机动画的制作