我正在使用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 –