设为首页 加入收藏

TOP

Android 选项卡(TabHost)例子(二)
2014-11-24 11:10:56 来源: 作者: 【 】 浏览:2
Tags:Android 选项 TabHost 例子


android:layout_gravity="center"
android:src="@drawable/help"/>






Activity文件 TabDemo.java




import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.widget.TabHost;
import android.widget.Toast;
import android.widget.TabHost.OnTabChangeListener;


import com.kf.samples5.R;


public class TabDemo extends Activity {


@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.tab);
TabHost host = (TabHost)findViewById(R.id.tabhost);
host.setup();


TabHost.TabSpec homeSpec = host.newTabSpec("Home"); //This


param will be used as tabId.
homeSpec.setIndicator(null, //This param will diplay as title.
getResources().getDrawable(R.drawable.home_normal));
homeSpec.setContent(R.id.tab1);
host.addTab(homeSpec);


TabHost.TabSpec garbageSpec = host.newTabSpec("Garbage");
garbageSpec.setIndicator(null, getResources().getDrawable


(R.drawable.garbage_normal));
garbageSpec.setContent(R.id.tab2);
host.addTab(garbageSpec);


TabHost.TabSpec maybeSpec = host.newTabSpec("Help");
maybeSpec.setIndicator(null, getResources().getDrawable


(R.drawable.help_normal));
maybeSpec.setContent(R.id.tab3);
host.addTab(maybeSpec);


host.setOnTabChangedListener(new OnTabChangeListener() {


@Override
public void onTabChanged(String tabId) {
// TODO Auto-generated method stub
Toast toast = Toast.makeText(TabDemo.this, tabId, Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER_HORIZONTAL, 0, 50);
toast.show();
}
});


// host.setCurrentTabByTag("Home");
Toast toast = Toast.makeText(TabDemo.this, "Home",


Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER_HORIZONTAL, 0, 50);
toast.show();
}
}


首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇编译Linux 2.6.8.1版本内核并从新.. 下一篇Android原理揭秘系列之VacantCell..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·有没有哪些高效的c++ (2025-12-27 08:20:57)
·Socket 编程时 Accep (2025-12-27 08:20:54)
·计算机网络知识点总 (2025-12-27 08:20:52)
·一篇说人话的文章, (2025-12-27 07:50:09)
·Python Web框架哪家 (2025-12-27 07:50:06)