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(); 

这种方式,你会根据你的屏幕上获得的价值。