Reputation: 4794
I use this example for creating custom tab. I don't know how to add image in tab view.
I try adding ImageView
element in tabs_bg.xml but image is not displayed, only text
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imgTab"
android:background="@drawable/img"/>
Can someone help me with this?
Thanks
Upvotes: 1
Views: 4437
Reputation: 19220
You must specify the android:src
attribute for the ImageView
:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imgTab"
android:src="@drawable/img"/>
With no content (src), its size will be 0x0 (due to wrap_content
).
Specifying the indicator (header) of a tab view is made from java code, usually chained:
myTabHost.newTabSpec(tag).setIndicator(myTab).setContent(intent);
where myTabHost
is your TabHost
instance, and myTab
is a View
instance that will be used as the header of this tab.
You can create your own tab: define its layout in xml and add all the views (image, text...) you need on it.
For reference (complete sample) see the update part of this answer.
The layout/tab.xml
file contains the layout of the tab headers (including an icon too).
Upvotes: 2