2017-06-29 16 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 –

相关问题