3

最近、Jelly Bean デバイスでアプリをテストしたところ、Actionbar Dodging Code が機能しなくなっていることに気付きました。

OverlayMode が true の透明な Actionbar がありますが、一部の画面では Actionbar をソリッド アクションバーのように動作させたいと考えています。

これを機能させるために、ハニカムギャラリーコードからいくつかのコードを借りました

基本的に、私は 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 を変更しましたか?

4

1 に答える 1

4

ここで自分の質問に答えます。まず、コードにタイプミスがありました:

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

しかし、本当の問題は

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

Statusbarを含む画面全体のビューを提供します。Android 4.1 Jelly Bean のみ

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

透明アクションバーの下にプッシュする必要がある RootContentView を提供します。

于 2012-07-31T14:34:02.257 に答える