Android
[Android] Camera StatusBar Transparency
yenne
2019. 8. 22. 16:15
카메라를 화면에서, StatusBar까지 카메라 영역으로 잡고 싶다면,
(Status Bar의 Component들은 보이는 채로. 아예 안 보이게 하려면 그냥 Full Screen에 대해 검색해 보면 됩니다.)
일단 styles.xml의 App Theme안에 아래를 추가한다.
<item name="android:windowTranslucentStatus">true</item>
그러면 원래 만들어둔 Layout이 Status Bar만큼 위로 올라가게 되는데 (Status Bar영역까지 Layout을 채우기 때문에)
각 단말의 StatusBar 높이만큼 해당 레이아웃의 Top Margin값을 주면 되겠다.
public static int getStatusBarHeight(Context context) {
int result = 0;
int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
result = context.getResources().getDimensionPixelSize(resourceId);
}
return result;
}
public static void setMargins(View view, int left, int top, int right, int bottom) {
if (view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
ViewGroup.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
p.setMargins(left, top, right, bottom);
view.requestLayout();
}
}
StatusBarHeight값을 가져온 뒤, setMargin의 top에 집어 넣어서 레이아웃을 아래로 내림.
onCreate나 onCreateView에서 아래처럼 사용한다.
setMargins(mHeaderLayout, 0, getStatusBarHeight(getContext()), 0, 0);