0

AppBarLayout舉行ToolbarTabLayout。當視圖被錨定,高度被設置爲0 setLayoutParams(0)。在另一種狀態,認爲是崩潰了,我需要恢復appbar高度。我試過setLayoutParams(heightDp)其中設置AppBarLayout尺寸編程在Android

float heightDp = getResources().getDisplayMetrics().heightPixels/6; 

但是高度不準確。

private void setLayoutParams(int paramsHeight) { 
    CoordinatorLayout.LayoutParams lsp = (CoordinatorLayout.LayoutParams) mAppBarLayout.getLayoutParams(); 
    lsp.height = paramsHeight; 
    mAppBarLayout.setLayoutParams(lsp); 
} 

如何以編程方式確定確切的AppBar高度。

回答

0

你應該從默認的資源與TypedArray得到它:

int mActionBarSize; 
TypedArray attrs= getContext().getTheme().obtainStyledAttributes(new int[] { android.R.attr.actionBarSize }); 
mActionBarSize = (int) attrs.getDimension(0, 0); 

您必須回收TypedArray

attrs.recycle(); 

這種方式,你會根據你的屏幕上獲得的價值。