Android 尝试使工具栏与片段活动一起工作。有什么想法吗?
我正在使用fragmentActivity,它已在MapreadyCallback上扩展,无法扩展activity或appcompat 这使我在setSupportActionBar上出错 爪哇:Android 尝试使工具栏与片段活动一起工作。有什么想法吗?,android,toolbar,android-fragmentactivity,Android,Toolbar,Android Fragmentactivity,我正在使用fragmentActivity,它已在MapreadyCallback上扩展,无法扩展activity或appcompat 这使我在setSupportActionBar上出错 爪哇: public class MapsActivity extends FragmentActivity implements OnMapReadyCallback toolbar = (Toolbar) findViewById(R.id.app_bar); setSupportActionBa
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
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
告诉您无法扩展到AppCompatActivity的错误是什么?您可以进行扩展,从而扩展(支持)FragmentActivity。您尝试过这个吗?好的,我扩展了AppCompatActivity,它可以正常工作,没有错误。现在,当我运行应用程序时,该栏不显示。有什么建议吗?我也有。现在错误消失了。但是,当我运行应用程序时,工具栏高度如何工具栏高度设置为wrap_content所以我仔细注意到…应用程序运行..工具栏显示,然后消失,我拉的平铺覆盖层覆盖了它。所以请将高度设置为50 dp并检查