【发布时间】:2012-07-26 08:51:50
【问题描述】:
我最近在 Jelly Bean 设备上测试了我的应用程序,发现我的 Actionbar Dodging Code 不再起作用了。
我有一个 OverlayMode 为 true 的透明操作栏,但希望在我的某些屏幕中让操作栏像实心操作栏一样。
为了使它工作,我从 Honeycomb Gallery Code借了一些代码
基本上我会检查 Acionbar Height 并将 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?
【问题讨论】:
标签: android android-layout android-actionbar android-4.2-jelly-bean