質問

最近、Jelly Beanデバイスで私のアプリをテストし、私のアクションバーのドッグコードはもう動作しないことに気づいた。

OverlayMode Trueを搭載した透明なアクションバーを持っていますが、アクションバーを自分の画面の中に柔軟なアクションバーのように振る舞いたいです。 この作業を、私は5Candroid%5chcgallery%5 utitlesFragment.java "Rel=" Nofollow ">コード

基本的に私はAcionbarの高さを確認し、Android.r.id.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コンテナのPerhabsを変更しましたか?

役に立ちましたか?

解決

OK私自身の質問に答えてください。 最初に私のコードに能動がありました:

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を与えます。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top