2

The ActionBar shadow can be removed with themes and the windowContentOverlay tag, but is it possible to dynamically remove and re-add it from code at runtime?

Same question here, which has not gotten any solving answers.

Community
  • 1
  • 1
Jakob Harteg
  • 9,587
  • 15
  • 56
  • 78
  • why don't you create and use a custom action-bar? then you can do any thing you want with it – Hamid Reza Jul 16 '14 at 21:59
  • Well, I don't know exactly what you mean by custom action bar, but the alternative would be to just remove the shadow from themes, and then add a custom shadow manually the places I need it. But this is just not very convenient, and there should be a way to remove the default one programmatically. – Jakob Harteg Jul 16 '14 at 22:02

1 Answers1

0

After struggling a while, I was able to write a solution for API > 21:

private ActionBar actionBar;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle instance) {
    // ...

    actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();

    return view;
}

@Override
public void onResume() {
    super.onResume();

    if (actionBar != null) {
        actionBar.setElevation(0);
    }
}

@Override
public void onPause() {
    super.onPause();

    if (actionBar != null) {
        actionBar.setElevation(getResources().getDimension(R.dimen.toolbar_elevation)); //8dp
    }
}

Hope this answer can help you by somehow, although have some while you asked that :

GuilhermeFGL
  • 2,891
  • 3
  • 15
  • 33