I am using TabHost to display a tabs bar at the bottom of the screen. Every tab has the same width although text in each tab is different. However, some tabs have short text and other tabs have long text. I want the tabs that contain short text has small width and long-width tabs have long text.
i tried running this code but error occurred .
android app development companies in UK
First, you have to get an instance of TabWidget. From the instance, you are able to get reference to a tab in the tab bar using getChildAt(int index) method. To set width of a tab, you create a LayoutParams object. With the layout params object, you can specify the width, height, and weight of the tab. Then, you set the layout params object to the tab using setLayoutParams() method of a ViewGroup instance that references to it. If you want to change the font size, font name, or font color of the tab, you make a reference to the textview in the tab calling the getChildAt() method of the ViewGroup.
Here is an example. In the example code, there are three tabs. The first and second tabs have the width. The third tab has longer width. The first two tabs contain icons and the last one tab has text content.
This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages: