0

I am using fragmentActivity, and it already extends OnMapReadyCallback, and cannot extend activity or appcompat.

THis gives me error on setSupportActionBar.

Java :

public class MapsActivity extends FragmentActivity implements 
 OnMapReadyCallback 

toolbar = (Toolbar) findViewById(R.id.app_bar);
setSupportActionBar(toolbar);

This is the error that comes up - Error:(80, 9) error: cannot find symbol method setSupportActionBar(Toolbar)

Activity Layout:

<include
    android:id="@+id/app_bar"
    layout="@layout/app_bar"/>

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    android:id="@+id/map"
    xmlns:tools="http://schemas.android.com/tools"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.pos.gisapp.MapsActivity" />

And the actual app_bar.xml :

<?xml version="1.0" encoding="utf-8"?>
 <android.support.v7.widget.Toolbar 
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:background="@color/colorPrimary"
   android:elevation="4dp">
</android.support.v7.widget.Toolbar>
  • What's the error telling you that you are not able to extend to AppCompatActivity? – Enzokie Jun 29 '17 at 09:47
  • You can extend [AppCompatActivity](https://developer.android.com/reference/android/support/v7/app/AppCompatActivity.html), which in turn extends (support) FragmentActivity. – RobCo Jun 29 '17 at 09:49
  • Have you tried this ? https://stackoverflow.com/questions/30148276/adding-toolbar-to-a-fragmentactivity – Nimisha V Jun 29 '17 at 09:50
  • Ok i Extended AppCompatActivity, and it all works no errors. Now the bar doesn show when i run app. Any suggestions? – Yeeshu Rastogi Jun 29 '17 at 13:33

1 Answers1

0

With the latest version of the support library, you should make your Activity extend AppCompatActivity

import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
Naveen Tamrakar
  • 3,349
  • 1
  • 19
  • 28