[英]Give dynamic height to bottom Tabbar?
現在,我將其固定為高度。 這是我的代碼。
我想根據屏幕分辨率將此高度設置為動態。
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);
}
}
我找到了問題的解決方案
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);
}
}
從以下方法獲取高度,您將為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;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.