Why is my icon for browser tab not showing up?
Try this, your comment end was in the wrong place
<!--
<![if !IE>
<link rel="icon" href="http://mywebsiteurl/images/favicon.ico" type="image/x-icon" />
<![endif]>
!-->
<link rel="shortcut icon" href="http://mywebsiteurl/images/favicon.ico" type="image/ico" />
Icon in Tab is not showing up
Have you tested your app on a device running Ice Cream Sandwich? I noticed recently, that the default TabHost
behaves differently depending on the target device and the android platform version.
Running an app that provides an icon and a text to setIndicator
(as in the source from the question), had the following test result:
- Phone with Android 2.1: both icon and text where shown (Label below the Icon as expected)
- Phone with 4.0.3: The icons didn't show and only the text was visible.
- Tablet running ICS: the tabs where shown with icon and text
As you found out too, replacing the label with an empty string the icons appeared on the Phone - but then the user would need to guess the meaning of the icons. Apart from that: When running this version of the app on the pre ICS phone: The tabs keep their size and leave an empty area below the image.
To change this device driven decision on how much space the tabs should get, I found the solution in this tutorial on how to customize tabs:
First you need to provide your own tab indicator layout ("layout/tab_indicator.xml" in the tutorial) including an ImageView
and a TextView
. Then you tell the TabSpec
to use this via setIndicator
. And voilà: you get the icon and the label on the phone with ICS too.
Here is the important part on how to set up the indicator (this = the current activity):
TabHost.TabSpec spec = this.getTabHost().newTabSpec(tag);
View tabIndicator = LayoutInflater.from(this).inflate(R.layout.tab_indicator, getTabWidget(), false);
((TextView) tabIndicator.findViewById(R.id.title)).setText(label);
((ImageView) tabIndicator.findViewById(R.id.icon)).setImageResource(drawableResourceId);
spec.setIndicator(tabIndicator);
If you like the same look of the tabs on older and newer phones have an additional look here:
http://jgilfelt.github.com/android-actionbarstylegenerator/. This page generates images and styles to customize the action bar including the tabs and helped me figure out how the 9-patch background images need to be defined.
Icons not showing in nested react-navigation bar
I found out what the problem was: I was adding the icon into the deepest (second) layer of the navigation bar. When using nested navigation bars, the icons must be placed in the highest level navigation layer. Here is a working version of the previous example, with the appropriate correction.
Tab icon not showing
//your are over loading the 1st one so you can see only the last added one
TabHost.TabSpec spec=tabs.newTabSpec("mitab1");
spec.setIndicator("sss",
res.getDrawable(android.R.drawable.ic_btn_speak_now));
Intent sssIntent = new Intent(this, First.class);
spec.setContent(sssIntent);
tabs.addTab(spec);
TabHost.TabSpec spec2=tabs.newTabSpec("mitab2");
spec2=tabs.newTabSpec("mitab2");
spec2.setIndicator("TAB2",
res.getDrawable(android.R.drawable.ic_dialog_map));
Intent sssIntent2 = new Intent(this, Second.class);
spec2.setContent(sssIntent2 );
tabs.addTab(spec2);
Related Topics
Activity Not Started, Its Current Task Has Been Brought to the Front
Android Play Services 6.5: Locationclient Is Missing
File Res/Drawable/Abc_Ic_Ab_Back_Material.Xml from Drawable Resource Id #0X7F020016
Gcm Service_Not_Available on Android 2.2
Firebase Auth Using Phone Number and Password
How to Send File Using Bluetooth on Android Programatically
How to Handle Outofmemoryerror
Horizontal Scrolling Grid View
Android Cancel Toast When Exiting the App and When Toast Is Being Shown
Datepicker Shows Wrong Value of Month
How to Change Action Bar Title Color in Code
How to Handle Multiple Countdown Timers in Listview
How to Get the Position Selected in a Recyclerview
How to Get the Google Username on Android
How to Wrap the Height of a Viewpager to the Height of Its Current Fragment