【问题标题】:Shadow under ActionBar when using ActionBarSherlock使用 ActionBarSherlock 时 ActionBar 下的阴影
【发布时间】:2012-09-09 18:33:40
【问题描述】:

我正在使用 ActionBarSherlock。在 Android 3.0+ 上,ActionBar 下方有一个微妙的阴影。但不是在较旧的 Android 上。

问题是,android:windowContentOverlay 中设置的阴影出现在活动窗口的顶部。在较旧的 Android 上,ActionBar 是 Window 的一部分。所以阴影覆盖在 ActionBar 的顶部,而不是覆盖在 ActionBar 下的内容。

有没有办法解决这个问题,而无需手动将阴影插入到每个 Activity 的布局中?

【问题讨论】:

  • 您可以更改 ActionBarSherlock 布局文件,或者创建一个自定义活动类并在布局中添加阴影(FrameLayout with shadow drawable),并从中扩展其他活动。
  • 谢谢,我会做第二个。我觉得很愚蠢,现在这似乎很明显:)

标签: android android-actionbar actionbarsherlock


【解决方案1】:

正如@wingman 在 cmets 中所暗示的那样,我在我的基础 Activity 中覆盖了 setContentView(...),如下所示:

@Override
public void setContentView(int layoutResId) {
    View view = getLayoutInflater().inflate(layoutResId, null);
    setContentView(view);
}

@Override
public void setContentView(View view) {
    int wrapContent = ViewGroup.LayoutParams.WRAP_CONTENT;
    int matchParent = ViewGroup.LayoutParams.MATCH_PARENT;
    view.setLayoutParams(new ViewGroup.LayoutParams(matchParent, matchParent));

    View shadow = new View(this);
    shadow.setBackgroundResource(R.drawable.action_bar_shadow);
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(matchParent,
            wrapContent);
    shadow.setLayoutParams(params);

    RelativeLayout container = new RelativeLayout(this);
    container.addView(view);
    container.addView(shadow);

    super.setContentView(container);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多