多亏了 TabSpec,我想在我的 TabHost 中显示一个视图,它确实适用于除 Nexus 7 之外的所有设备。
Drawable img = getResources().getDrawable(R.drawable.tab_info_icon);
Intent intent = new Intent(context, Actus.class);
setupTab(img, intent);
private void setupTab(final Drawable image, final Intent intent) {
View tabview = createTabView(mTabHost.getContext(),image, intent);
TabSpec setContent = mTabHost.newTabSpec("").setIndicator(tabview).setContent(intent);
mTabHost.addTab(setContent);
}
private static View createTabView(final Context context, final Drawable image,final Intent intent) {
View view = LayoutInflater.from(context).inflate(R.layout.onglet, null);
LinearLayout ll = (LinearLayout)view.findViewById(R.id.fondOnglet);
ll.setBackgroundResource(R.drawable.tab_bg);
ImageView iv = (ImageView)view.findViewById(R.id.imgOnglet);
iv.setImageDrawable(image);
return view;
}
R.drawable.tab_info_icon 是一个 xml 选择器。