Question

i recently tested my App on a Jelly Bean device and noticed that my Actionbar Dodging Code doesnt work anymore.

I have a transparent Actionbar with OverlayMode true but want to behave the Actionbar like a solid actionbar in some of my Screens.

To make this working i have borrowed some Code from the Honeycomb Gallery Code

Basicly i check the Acionbar Height and set the topMargin of the android.R.id.content bucket to this value.

  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);
          }
        }

      }

In Jelly Beans this strategy doesnt work anymore for some reason. Did Jelly Bean change the id.content Container perhabs?

Was it helpful?

Solution

Ok answering my own Question here. First i had a typo in my Code:

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

But the real Problem was that

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

provide the View of the whole Screen, including the Statusbar. Only on Android 4.1 Jelly Bean

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

gives the RootContentView that needs to be pushed under the Transparent Actionbar.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top