展会信息港展会大全

android开发以FrameLayout为主TabHost分页视图
来源:互联网   发布日期:2015-10-03 11:11:44   浏览:1838次  

导读:TabHost的xml文件必须是要以FrameLayout为主,例如下面是三个分页的文本视图:java代码如下:TabHost tabHost = this getTabHost();LayoutInflater from(this) inflate(R layout main, tabHost getTabConten ...

TabHost的xml文件必须是要以FrameLayout为主,例如下面是三个分页的文本视图:

java代码如下:

TabHost tabHost = this.getTabHost();

LayoutInflater.from(this).inflate(R.layout.main, tabHost.getTabContentView(),

true);

tabHost.addTab(tabHost.newTabSpec("Tab_1").setContent

(R.id.tab1).setIndicator("添加",this.getResources().getDrawable

(R.drawable.ic_launcher)));

tabHost.addTab(tabHost.newTabSpec("Tab_2").setContent

(R.id.tab2).setIndicator("修改",this.getResources().getDrawable

(R.drawable.ic_launcher)));

tabHost.addTab(tabHost.newTabSpec("Tab_3").setContent

(R.id.tab3).setIndicator("删除",this.getResources().getDrawable

(R.drawable.ic_launcher)));

//分页视图头,

tabHost.setCurrentTab(1);//初始化为第二页,其index从0开始

tabHost.setOnTabChangedListener(new OnTabChangeListener() {

@Override

public void onTabChanged(String tabId) {

// TODO Auto-generated method stub;

AlertDialog dia=new AlertDialog.Builder(Tabactivity.this).setTitle("提示").setMessage("选 中了" + tabId +"选项卡").setPositiveButton("确定", new DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialog, int which) {

// TODO Auto-generated method stub

dialog.cancel();

}

}).create();

dia.show();

}

});

android中tabHost设置标题的颜色和大小

TabWidget tabWidget = this.getTabWidget();//TabHost中有一个getTabWidget()的方法

for (int i = 0; i < tabWidget.getChildCount(); ++i){

TextView tv = (TextView)tabWidget.getChildAt(i).findViewById(android.R.id.title);

tv.setGravity(BIND_AUTO_CREATE);

tv.setPadding(10, 10,10, 10);

tv.setTextSize(16);//设置字体的大小;

tv.setTextColor(Color.WHITE);//设置字体的颜色;

//获取tabs图片;

ImageView iv=(ImageView)tabWidget.getChildAt(i).findViewById(android.R.id.icon);

}

//设置tabHost的高度

for (int i = 0; i < tabWidget.getChildCount(); i++) {

View view = tabWidget.getChildTabViewAt(i);

view.getLayoutParams().height = 80; //tabWidget.getChildAt(i)

final TextView tv = (TextView) view.findViewById(android.R.id.title);

tv.setTextSize(28);

tv.setTextColor(this.getResources().getColorStateList(

android.R.color.white));

赞助本站

人工智能实验室

相关热词: TabHost 分页 FrameLayout android

相关内容
AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港