我最近在 Jelly Bean 设备上测试了我的应用程序,发现我的操作栏躲避代码不再起作用。
我有一个 OverlayMode 为 true 的透明操作栏,但希望在我的某些屏幕中将操作栏表现得像一个实心操作栏。
为了使它工作,我从 Honeycomb Gallery Code借了一些代码
基本上我检查 Acionbar 高度并将 android.R.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);
}
}
}
在 Jelly Beans 中,由于某种原因,这种策略不再起作用。Jelly Bean 是否更改了 id.content Container perhabs?