我正在使用fragmentActivity,它已经扩展了OnMapReadyCallback,并且不能扩展活动或appcompat。试图使工具栏与片段活动一起工作。有任何想法吗?
这给我错误setSupportActionBar。
的Java:
public class MapsActivity extends FragmentActivity implements
OnMapReadyCallback
toolbar = (Toolbar) findViewById(R.id.app_bar);
setSupportActionBar(toolbar);
这是出现的错误 - 错误:(80,9)错误:无法找到符号方法setSupportActionBar(工具栏)
活动布局:
<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" />
而实际的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>
什么错误告诉你,你是不是能够延伸到AppCompatActivity? – Enzokie
您可以扩展[AppCompatActivity](https://developer.android.com/reference/android/support/v7/app/AppCompatActivity.html),然后扩展(支持)FragmentActivity。 – RobCo
你试过这个吗? https://stackoverflow.com/questions/30148276/adding-toolbar-to-a-fragmentactivity –