for (int i = 0i <tabWidget.getChildCount()i++) {
//有文字设置文字
TextView textView = (TextView) tabWidget.getChildAt(i)
.findViewById(android.R.id.title)
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) textView
.getLayoutParams()
params.setMargins(10, 50, 10, 2)// 设置控件位置,数字自己调
textView.setLayoutParams(params)
textView.setTextSize(10)
//有图片设置图片
ImageView image = (ImageView) tabWidget.getChildAt(i).findViewById(
android.R.id.icon)
tabWidget.getChildAt(i).setBackgroundResource(R.color.dibian)// 设置背景,你应该少了这个
RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) image
.getLayoutParams()
params1.setMargins(10, 10, 10, 10)//数字自己调
image.setLayoutParams(params1)
image.getLayoutParams().height = 40// 通过给它的属性赋值的方法可以解决问题
image.getLayoutParams().width = 55//数字自己调
}
tabHost.addTab(tabHost.newTabSpec("abcd").setIndicator(myview).setContent(R.id.adfaf))
其中 setIndicator 就是你设置的view 这个view就可以包含你的背景图片
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)