Difference between setSupportActionBar and setActionBar

So I am trying to use a toolbar as an ActionBar in my application. I am trying to use a method setSupportActionBar()

in a fragment that is hosted in an activity that extends a class that extends AppCompatActivity

. For some reason I cannot do at all getActivity().setSupportActionBar()

, I can only do getActivity().setActionBar()

. The problem is that setSupportActionBar()

accepts android.support.v7.widget.Toolbar

where setActionBar()

only the android.widget.Toolbar file is accepted. This forces my application to be limited to only devices using Lollipop.

I found that when trying to change the toolbar theme to dark with

app:theme="@style/ThemeOverlay.AppCompat.Dark"

      

he does not work.

+3


source to share


1 answer


getActivity()

has a class Activity

even if yours Activity

is a kind of subclass AppCompatActivity

. You have to push getActivity()

, call

((AppCompatActivity)getActivity()).setSupportActionBar()

      



For Issue Topic, you should post the details of where you put which style definition, or rather, put it in a separate question.

+4


source







All Articles