Wen i add setSupportActionBar(toolbar); in my fragment, its show me this error: Cannot resolve method 'setSupportActionBar(toolbar)'
private DatabaseReference referencia;
private FirebaseAuth autenticacao;
private Toolbar toolbar;
private View view;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragmento_chat, container, false);
toolbar = view.findViewById(R.id.frag_chat_barra_layout);
setSupportActionBar(toolbar);
You can set Support ActionBar in Fragment as follow:
((AppCompatActivity)getActivity()).setSupportActionBar(toolbar);
setSupportActionBar
method is available only to the Activity class that you inherit.
Hence to solve the problem, do this:
((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.