Because the image resources in the project are all renewed from the Internet, the figure in tabwidget is too large to overwrite the text. The initial effect is as follows:
Most of the search results on the Internet are about how to change the font size and color. The code below sets the font color and size of tabs in tabhost;
Tabwidget = This. gettabwidget ();
For (INT I = 0; I <tabwidget. getchildcount (); I ++ ){
Textview TV = (textview) tabwidget. getchildat (I). findviewbyid (Android. R. Id. Title );
TV. setgravity (bind_auto_create );
TV. setpadding (10, 10, 10, 10 );
TV. settextsize (16); // set the font size;
TV. settextcolor (color. White); // you can specify the font color;
// Obtain the tabs image;
Imageview IV = (imageview) tabwidget. getchildat (I). findviewbyid (Android. R. Id. Icon );
} Based on the above example, we estimate that two methods will be used to solve the problem 1. For (INT I = 0; I <tabwidget. getchildcount (); I ++ ){
// Obtain the tabs image;
Imageview IV = (imageview) tabwidget. getchildat (I). findviewbyid (Android. R. Id. Icon );
Iv. setmaxheight (30 );
Iv. setmaxwidth (30 );
} So we can find that there is still no effect 2. For (INT I = 0; I <tabwidget. getchildcount (); I ++ ){
// Obtain the tabs image;
Imageview IV = (imageview) tabwidget. getchildat (I). findviewbyid (Android. R. Id. Icon );
Iv. setlayoutparams (New layoutparams (width, height ));
}
But in this case, the program will go wrong. Why? Because layoutparams (width, height) of the parent control must be used in new layoutparams, while we did not find any suitable organization import when importing the package, all the results found that no matter which one will go wrong, 3. Therefore, we must seek another method for (INT I = 0; I <tabs. getchildcount (); I ++)
{
Textview = (textview) tabs. getchildat (I). findviewbyid (Android. R. Id. Title );
Textview. settextsize (14 );
Textview. setpadding (0, 3, 0, 0 );
Imageview image = (imageview) tabs. getchildat (I). findviewbyid (Android. R. Id. Icon );
Image. getlayoutparams (). Height = 30; // you can solve the problem by assigning values to its attributes.
Image. getlayoutparams (). width = 30;
} The result is the initial goal.