2014-05-22 4 views
1

Хорошо, быстрый фон: я разрабатывал приложение для простого музыкального плеера и улучшал пользовательский интерфейс (особенно на более новых устройствах). Я решил реализовать тонированное StatusBar, используя fabled SystemBarTint library.Мой фрагмент был перекрыт вкладками ActionBar при использовании SystemBarTint

Импортировано .JAR, последовали указания использования, изменили тему приложения и вуаля! Мое приложение выглядит более привлекательным, чем 10-летний шоу-байк. Но подождите, есть еще!

enter image description here

Как вы можете видеть, ListView теперь покрывается ActionBar и его закладках. Я сделал домашнее задание и нашел this обходной путь - который работает, вроде.

enter image description here

Мои ListView больше не покрываются ActionBar, но она по-прежнему покрыта закладками!

Как мне разобрать этот?

Это мой BaseActivityonCreate метод, который активирует 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()); 
} 

Спасибо заранее!

ответ

1

Его немного поздно, но я столкнулся с той же проблемой. Мое решение добавить этот метод:

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()); 
Смежные вопросы