将图像添加到自定义选项卡
问题描述:
我使用this示例创建自定义选项卡。我不知道如何在选项卡视图中添加图像。将图像添加到自定义选项卡
我尝试在tabs_bg.xml但图像添加ImageView
元素不显示,只有文字
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imgTab"
android:background="@drawable/img"/>
有人可以帮助我?
感谢
答
您必须指定ImageView
的android:src
属性:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imgTab"
android:src="@drawable/img"/>
没有内容(SRC),其规模将为0x0(由于wrap_content
)。
指定标签视图的指示(标题)被从Java代码制成,通常是链:
myTabHost.newTabSpec(tag).setIndicator(myTab).setContent(intent);
其中myTabHost
是您的TabHost
实例,myTab
是将被用作报头中的View
实例这个标签。
您可以创建自己的选项卡:在xml中定义其布局并添加所需的所有视图(图像,文本...)。请参考update part of this answer。 layout/tab.xml
文件包含选项卡标题的布局(也包括图标)。