【问题标题】:Jelly Bean android.R.id.content changed?果冻豆 android.R.id.content 变了?
【发布时间】: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


    【解决方案1】:

    好的,在这里回答我自己的问题。 首先,我的代码中有一个错字:

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

    但真正的问题是

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

    提供整个屏幕的视图,包括状态栏仅适用于 Android 4.1 Jelly Bean

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

    给出需要在透明Actionbar下推送的RootContentView。

    【讨论】:

      猜你喜欢
      • 2013-02-12
      • 2012-11-10
      • 2013-05-21
      • 1970-01-01
      • 2012-08-09
      • 1970-01-01
      • 2012-09-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多