-1

In my app I am using the tab layout.I want to modify the default height of the tab and I want to modify the tab label font without using customized tab. Is it possible? If yes, then how to implement it. Can anybody suggest me

public class HelloTabWidget extends TabActivity 
{

    public void onCreate(Bundle savedInstanceState) 
        {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);    

        TabHost tabHost = getTabHost();  // The activity TabHost                            
        addTab(tabHost,"Find Gifts","findgifts",R.drawable.findgifts,R.layout.tabs_bg);
        }


    public static void addTab(TabHost host, String title, String tag,
            int drawable, int layout) {
        TabHost.TabSpec spec = host.newTabSpec(tag);
        spec.setContent(layout);
        View view = prepareTabView(host.getContext(), title, drawable);
        spec.setIndicator(view);
        host.addTab(spec);

    }

    private static View prepareTabView(Context context, String title,
            int drawable) {
         View view = LayoutInflater.from(context).inflate(R.layout.tabs_bg, null);

         ImageView tabicon = (ImageView) view.findViewById(R.id.tabicon);
         tabicon.setImageResource(drawable);

         TextView tabtext = (TextView) view.findViewById(R.id.tabsText);
         tabtext.setText(title);             

          return view;
    }
  }

Trace:

10-04 13:13:43.851: ERROR/AndroidRuntime(3734): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.tab/com.example.tab.HelloTabWidget}:  

java.lang.RuntimeException: Could not create tab content because could not find view with id 2130903042

10-04 13:13:43.851: ERROR/AndroidRuntime(3734): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
Sathyajith Bhat
  • 21,321
  • 22
  • 95
  • 134
naresh
  • 10,332
  • 25
  • 81
  • 124

2 Answers2

1

The following code adjusts the height on the tabs:

for (int i = 0; i < tabHost.getTabWidget().getTabCount(); i++)

{
 tabHost.getTabWidget().getChildAt(i).getLayoutParams().height = 33; 
}  
Sathyajith Bhat
  • 21,321
  • 22
  • 95
  • 134
kalpana c
  • 2,739
  • 3
  • 27
  • 47
0

There are many resources which I can point you to:

and this answer

edit:

The view that you are trying to findViewById() is not present in R.layout.main

Community
  • 1
  • 1
Reno
  • 33,594
  • 11
  • 89
  • 102
  • Yes, if you want to modify the look and feel, you have to use some form of customization. – Reno Oct 04 '11 at 07:33