Hadi Satrio
Hadi Satrio

Reputation: 4292

My Fragment got overlapped by ActionBar Tabs when using SystemBarTint

Okay, a quick background : I've been developing a simple music player app and to enhance the user experience (especially on newer devices) I decided to implement a tinted StatusBar using the fabled SystemBarTint library.

Imported the .JAR, followed the usage directions, modified the application theme and voila! My app looks fancier than an 10-years old show bike. But wait, there's more!

enter image description here

As you can see, the ListView is now covered by the ActionBar and its tabs. I did my homework and found this workaround -- which works, sort of.

enter image description here

My ListView is no longer covered by the ActionBar but it's still covered by the tabs!

How do I sort this one out?

This is my BaseActivity onCreate method which activates the SystemBarTint library :

@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));
} 

..and this is the workaround, supplied in my Fragment (which houses the 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());
}

Thanks in advance!

Upvotes: 1

Views: 421

Answers (1)

Frederico Silva
Frederico Silva

Reputation: 328

Its a little late, but I was facing the same problem. My solution is add this method:

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;
}

and replace:

view.setPadding(0, config.getPixelInsetTop(true),
        config.getPixelInsetRight(), config.getPixelInsetBottom());

with:

view.setPadding(0, config.getPixelInsetTop(true) + getActionBarHeight(),
        config.getPixelInsetRight(), config.getPixelInsetBottom());

Upvotes: 1

Related Questions