我最近在果冻bean设备上测试了我的应用程序,并注意到我的actionbar躲闪代码不再工作了。

我有一个透明的actionBar,occorDayMode是真的,但想要在一些屏幕中就像一个稳定的动作栏一样行事。 要使这个工作我已经从Honeycomb Gallery借用了一些代码代码

基本上我检查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);
          }
        }

      }
.

在果冻豆中,这种策略因某种原因而不再工作了。果冻bean更改了id.Content容器perhabs吗?

有帮助吗?

解决方案

好的在这里回答我自己的问题。 首先我在我的代码中有一个拼写号:

content.setLayoutParams(params); should read
content.setLayoutParams(lp);
.

但实际问题是

FrameLayout content = (FrameLayout) findViewById(android.R.id.content);
.

提供整个屏幕的视图,包括 statusbar 只在Android 4.1果冻bean

View content = ((ViewGroup) findViewById(android.R.id.content)).getChildAt(0);
.

给出需要在透明actionbar下推送的rootContentView。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top