菜单未显示在工具栏上

时间:2016-11-02 19:40:16

标签: android android-toolbar appcompatactivity

我按照本指南(https://developer.android.com/training/appbar/setting-up.html)为我的活动设置了操作栏,但我无法显示菜单按钮(右上方3条水平线)。

我正在扩展AppCompatActivity并使用GoogleMap Fragment,它正确显示在我的操作栏下方。

在我设定的清单中:

android:theme="@style/Theme.AppCompat.Light.NoActionBar" 

按照指南的指示。

菜单资源文件

<?xml version="1.0" encoding="utf-8"?>
<menu
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto" >

    <item
        android:id="@+id/action_settings"
        android:title="@string/action_settings"
        app:showAsAction="always" />


</menu>

工具栏xml

<android.support.v7.widget.Toolbar
    android:id="@+id/my_toolbar"
    android:title="@string/toolbar_title"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    android:elevation="4dp"
    android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

的onCreate

@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.i(LOG_TAG, "onCreate");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);

    //Toolbar
    Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
    myToolbar.inflateMenu(R.menu.menu_activity_maps);
    setSupportActionBar(myToolbar);
    getSupportActionBar().setTitle("yoyo");

    //Obtain the SupportMapFragment and call onMapReady when it is ready to be used
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
}

如何显示菜单?

1 个答案:

答案 0 :(得分:0)

你很接近,但是你错过了那个页面上的一个链接:

https://developer.android.com/training/appbar/actions.html

基本上您只是定义了工具栏,但您还必须定义其上的所有项目以及单击时应采取的操作。

“drawable”是使用什么图像。这是心脏。

Showing Recent Issues
ld: warning: ld: warning: ld: warning: ignoring file /Users/jb/Library/Developer/Xcode/DerivedData/Give_It_Up_and_Trade-efbegnisuhotnyharswslfockoid/Build/Products/Debug-iphoneos/libFMDB.a, file was built for archive which is not the architecture being linked (arm64): /Users/jb/Library/Developer/Xcode/DerivedData/Give_It_Up_and_Trade-efbegnisuhotnyharswslfockoid/Build/Products/Debug-iphoneos/libFMDB.aignoring file /Users/jb/Library/Developer/Xcode/DerivedData/Give_It_Up_and_Trade-efbegnisuhotnyharswslfockoid/Build/Products/Debug-iphoneos/libFontAwesomeKit.a, file was built for archive which is not the architecture being linked (arm64): /Users/jb/Library/Developer/Xcode/DerivedData/Give_It_Up_and_Trade-efbegnisuhotnyharswslfockoid/Build/Products/Debug-iphoneos/libFontAwesomeKit.aignoring file /Users/jb/Library/Developer/Xcode/DerivedData/Give_It_Up_and_Trade-efbegnisuhotnyharswslfockoid/Build/Products/Debug-iphoneos/libAFNetworking.a, file was built for archive which is not the architecture being linked (arm64): /Users/jb/Library/Developer/Xcode/DerivedData/Give_It_Up_and_Trade-efbegnisuhotnyharswslfockoid/Build/Products/Debug-iphoneos/libAFNetworking.a


ld: warning: ignoring file /Users/jb/Library/Developer/Xcode/DerivedData/Give_It_Up_and_Trade-efbegnisuhotnyharswslfockoid/Build/Products/Debug-iphoneos/libRMStore.a, file was built for archive which is not the architecture being linked (arm64): /Users/jb/Library/Developer/Xcode/DerivedData/Give_It_Up_and_Trade-efbegnisuhotnyharswslfockoid/Build/Products/Debug-iphoneos/libRMStore.a


ld: warning: ignoring file /Users/jb/Library/Developer/Xcode/DerivedData/Give_It_Up_and_Trade-efbegnisuhotnyharswslfockoid/Build/Products/Debug-iphoneos/libUIColor-Crayola.a, file was built for archive which is not the architecture being linked (arm64): /Users/jb/Library/Developer/Xcode/DerivedData/Give_It_Up_and_Trade-efbegnisuhotnyharswslfockoid/Build/Products/Debug-iphoneos/libUIColor-Crayola.a


  "_OBJC_CLASS_$_RMStore", referenced from:


      objc-class-ref in iapClass.o


  "_OBJC_CLASS_$_RMAppReceipt", referenced from:


      objc-class-ref in iapClass.o


  "_OBJC_CLASS_$_FAKFontAwesome", referenced from:


      objc-class-ref in browseViewController.o


      objc-class-ref in FirstViewController.o


  "_OBJC_CLASS_$_AFJSONRequestSerializer", referenced from:


      objc-class-ref in networkingClass.o


  "_OBJC_CLASS_$_AFHTTPSessionManager", referenced from:


      objc-class-ref in networkingClass.o


ld: symbol(s) not found for architecture arm64


clang: error: linker command failed with exit code 1 (use -v to see invocation)

您可以通过Android Studio创建自己的drawable,方法是转到File-&gt; New-&gt; Image Asset,然后切换到“Action Bar和Tab Icons”。有很多可供选择,包括你感兴趣的垂直点。