Why do I TabHost setIndicator to set up the picture, but I use but does not show


// th_host = (TabHost) this.findViewById(R.id.th_host);
th_host = getTabHost();
TabSpec ts_list = th_host.newTabSpec("List");
ts_list.setIndicator("List",
getResources().getDrawable(R.drawable.list));
ts_list.setContent(R.id.lv_address);
th_host.addTab(ts_list);
TabSpec ts_edit = th_host.newTabSpec("Edit");
ts_edit.setIndicator("Add to",
getResources().getDrawable(R.drawable.restaurant));
ts_edit.setContent(R.id.tb_details);
th_host.addTab(ts_edit);


Where there is a problem?

Thank you

Started by Cliff at December 11, 2016 - 7:33 PM

I found that if the settings I delete Manifest the following can be displayed
This is why, ?

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />

Posted by Cliff at December 21, 2016 - 7:43 PM

Personal feeling is as follows:
Now the code does not support to display images and text, you see the system source code, in TabHost.java.
final boolean exclusive = iconView.getVisibility() == View.GONE;
final boolean bindIcon = !exclusive || TextUtils.isEmpty(mLabel);
if (bindIcon && mIcon != null) {
iconView.setImageDrawable(mIcon);
iconView.setVisibility(VISIBLE);
}


There is a exclusive judge whether the ImageView display. Look at the corresponding tab_indicator_holo.xml file.
<ImageView
android:id="@android:id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:visibility="gone" />

See no, here is not to display images, that is to say, only in the text is empty when the display picture.
Personal understanding is Android own definition of the layout.
If you put the code in AndroidManifest.xml removed:
	    <uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />

Can display, should be before the code to support dual display. The above personal thoughts.

Posted by Brant at January 02, 2017 - 8:31 PM