jelly bean android.r.id.Content가 변경 되었습니까?
-
11-12-2019 - |
문제
나는 최근에 젤리 빈 장치에서 내 앱을 테스트하고 내 액션 표시 줄을 피하고 코드가 더 이상 작동하지 않는다는 것을 알아 차렸다.
오버레이 모드가 true가있는 투명한 액션 표시 줄이 있지만 일부 화면에서 솔리드 액션 바와 같은 액션 바를 작동시키고 싶습니다.
이 작업을 수행하려면 HoneyComb 갤러리에서 몇 가지 코드를 빌 렸습니다. href="http://android.okhelp.cz/java_android_code.php?o=%5Candroid-15%5ChoneyCombgallery%5csrc%5ccom5ccom5csrc%5ccom5cexample%5Candroid % 5ChCgallery % 5ctitlesfragment.java "rel="nofollow "> 코드
기본적으로 AcionBar 높이를 확인하고 Android.r.ID.ID.Content 버킷의 topmargin을이 값으로 설정합니다.
public void setupActionbar() {
final int sdkVersion = Build.VERSION.SDK_INT;
int barHeight = getSupportActionBar().getHeight();
if (sdkVersion < Build.VERSION_CODES.HONEYCOMB) {
FrameLayout content = (FrameLayout) findViewById(android.R.id.content);
RelativeLayout.LayoutParams params = (android.widget.RelativeLayout.LayoutParams) content.getLayoutParams();
if (params.topMargin != barHeight) {
params.topMargin = barHeight;
content.setLayoutParams(params);
}
if (!getSupportActionBar().isShowing()) {
params.topMargin = 0;
content.setLayoutParams(params);
}
} else {
FrameLayout content = (FrameLayout) findViewById(android.R.id.content);
LayoutParams params = content.getLayoutParams();
if (params instanceof RelativeLayout.LayoutParams) {
android.widget.RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) params;
if (lp.topMargin != barHeight) {
lp.topMargin = barHeight;
content.setLayoutParams(lp);
}
if (!getActionBar().isShowing()) {
lp.topMargin = 0;
content.setLayoutParams(lp);
}
} else if (params instanceof FrameLayout.LayoutParams) {
FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) params;
if (lp.topMargin != barHeight) {
lp.topMargin = barHeight;
content.setLayoutParams(params);
}
if (!getActionBar().isShowing()) {
lp.topMargin = 0;
content.setLayoutParams(params);
}
}
}
.
젤리 콩 에서이 전략은 어떤 이유로 더 이상 일하지 않습니다.젤리 빈은 id.Content 컨테이너 perhabs를 변경 했습니까?
해결책
OK 내 자신의 질문에 답하고 있습니다. 먼저 내 코드에서 오타가있었습니다.
content.setLayoutParams(params); should read
content.setLayoutParams(lp);
.
그러나 실제 문제는
FrameLayout content = (FrameLayout) findViewById(android.R.id.content);
.
statusbar 을 포함하여 전체 화면의보기를 제공합니다. 안드로이드 4.1 젤리 빈
.
View content = ((ViewGroup) findViewById(android.R.id.content)).getChildAt(0);
는 투명한 액션 표시 줄 아래에서 푸시 해야하는 rootContentView를 제공합니다.