2

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

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

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

4

1 回答 1

1

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

@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);
}
于 2012-09-09T20:04:03.130 回答