2017-06-29 27 views
0

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

什麼錯誤告訴你,你是不是能夠延伸到AppCompatActivity? – Enzokie

+0

您可以擴展[AppCompatActivity](https://developer.android.com/reference/android/support/v7/app/AppCompatActivity.html),然後擴展(支持)FragmentActivity。 – RobCo

+0

你試過這個嗎? https://stackoverflow.com/questions/30148276/adding-toolbar-to-a-fragmentactivity –

回答

0

的支持庫的最新版本,你應該讓你的Activity延長AppCompatActivity

import android.support.v7.app.AppCompatActivity; 
import android.support.v7.widget.Toolbar; 
+0

也得到了。現在錯誤消失了。但酒吧沒有顯示,當我運行的應用程序 –

+0

那麼工具欄高度 –

+0

工具欄高度設置爲wrap_content –

相關問題