好的,快速介绍一下背景:我一直在开发一个简单的音乐播放器应用程序,为了增强用户体验(尤其是在较新的设备上),我决定使用传说中的 SystemBarTint library 实现一个有色 StatusBar。 .
导入 .JAR,遵循使用说明,修改应用程序主题,瞧!我的应用程序看起来比 10 年前的表演自行车更漂亮。 等等,还有更多!
如您所见,ListView
现在被 ActionBar
及其选项卡覆盖。我做了功课,找到了this变通办法——在某种程度上是可行的。
我的 ListView
不再被 ActionBar
覆盖但它仍然被选项卡覆盖!
我该如何解决这个问题?
这是我的 BaseActivity
onCreate
激活 SystemBarTint
库的方法:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SystemBarTintManager tintManager = new SystemBarTintManager(this);
tintManager.setStatusBarTintEnabled(true);
tintManager.setTintColor(getResources().getColor(R.color.wowza_orange));
}
..这是解决方法,在我的 Fragment
(包含 ListView
)中提供:
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
musicList.setClipToPadding(false); // musicList is my ListView instance.
setInsets(getActivity(), (View) musicList);
}
public static void setInsets(Activity context, View view) {
SystemBarTintManager tintManager = new SystemBarTintManager(context);
SystemBarTintManager.SystemBarConfig config = tintManager.getConfig();
view.setPadding(0, config.getPixelInsetTop(true),
config.getPixelInsetRight(), config.getPixelInsetBottom());
}
提前致谢!
最佳答案
有点晚了,但我遇到了同样的问题。我的解决方案是添加此方法:
private int getActionBarHeight() {
int actionBarHeight =0;
final TypedValue tv = new TypedValue();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true))
actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
} else if (context.getTheme().resolveAttribute(R.attr.actionBarSize, tv, true))
actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
return actionBarHeight;
}
并替换:
view.setPadding(0, config.getPixelInsetTop(true),
config.getPixelInsetRight(), config.getPixelInsetBottom());
与:
view.setPadding(0, config.getPixelInsetTop(true) + getActionBarHeight(),
config.getPixelInsetRight(), config.getPixelInsetBottom());
关于android - 使用 SystemBarTint 时,我的 fragment 被 ActionBar 选项卡重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23803876/