i am not getting icon for customized tab
In my app i am using the customized tab. Here i am adding icons pro-grammatically to the image view. the images are adding correctly except to the first tab. please can anybody help me. Following is my code.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabsLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/tab_bg_selector"
android:padding="2dip"
android:gravity="center"
android:orientation="vertical">
<ImageView android:id="@+id/tabicon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView android:id="@+id/tabsText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title"
android:textSize="12dip"
android:textColor="@drawable/tab_text_selector"
/>
</LinearLayout>
Java code
public class CustomTabActivity extends Activity {
private TabHost mTabHost;
private void setupTabHost() {
mTabHost = (TabHost) findViewById(android.R.id.tabhost);
mTabHost.setup();
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// construct the tabhost
setContentView(R.layout.main);
setupTabHost();
mTabHost.getTabWidget().setDividerDrawable(R.drawable.tab_divider);
setupTab(new TextView(this), "Find Gifts",R.drawable.findgifts);
setupTab(new TextView(this), "Tracked Items",R.drawable.items);
setupTab(new TextView(this), "Preferences",R.drawable.preferences);
}
private void setupTab(final View view, final String tag,int drawable) {
View tabview = createTabView(mTabHost.getContext(), tag, drawable);
TabSpec setContent = mTabHost.newTabSpec(tag).setIn开发者_开发技巧dicator(tabview).setContent(new TabContentFactory() {
public View createTabContent(String tag) {
return view;
}
});
mTabHost.addTab(setContent);
}
private static View createTabView(final Context context, final String text,int drawable) {
View view = LayoutInflater.from(context).inflate(R.layout.tabs_bg, null);
ImageView tabicon = (ImageView) view.findViewById(R.id.tabicon);
tabicon.setBackgroundResource(drawable);
TextView tv = (TextView) view.findViewById(R.id.tabsText);
tv.setText(text);
return view;
}
}
TRY TO use form that
that provide the make tab with image
http://www.codeproject.com/KB/android/AndroidTabs.aspx
精彩评论