Search code examples
androidxmlandroid-studiotabbartabwidget

Give dynamic height to bottom Tabbar?


Now, I have make it with Fixed height. Here is my code.

I want to give this height as dynamic according to screen resolutions.

for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++)
{
    tabHost.getTabWidget().getChildAt(i).getLayoutParams().height = 130;
    if (i == 0)
    {
    tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#ffffff"));
    }
    else
    {
     tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.WHITE);
     }
}

Solution

  • I found the solution for my question

    for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++)
            {
                // Log.e("Selcted : ", ""+i);
                tabHost.getTabWidget().getChildAt(i).getLayoutParams().height = getHeight(getApplicationContext());
                if (i == 0)
                {
                    tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#ffffff"));
                }
                else
                {
                    tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.WHITE);
                }
            }
    

    Get height from below method and you will get perfect height for your Tabbar.

     public int getHeight(Context context)
        {
         Resources resources = context.getResources();
     int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
    if (resourceId > 0)
     {
    return resources.getDimensionPixelSize(resourceId);
    }
     return 0;
    }