我想制作地图活动,我想在操作栏中添加2个按钮。我使用Android Studio 0.8.4创建了项目,但我无法将菜单添加到操作栏。 请帮助我
mapview.xml:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/map"
tools:context=".MapsActivity"
android:name="com.google.android.gms.maps.SupportMapFragment"/>
Maps Activity.java
public class MapsActivity extends FragmentActivity implements LocationListener
{@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.mapmenu, menu);
// Calling super after populating the menu is necessary here to ensure that the
// action bar helpers have a chance to handle this event.
return true;
}
mapmenu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/action_search"
tools:ignore="AppCompatResource"
android:orderInCategory="50"
android:icon="@android:drawable/ic_menu_search"
android:title="Caută"
tools:showAsAction="ifRoom"/>
<item android:id="@+id/action_cagain"
android:icon="@drawable/ic_action_refresh"
android:title="Încearcă din nou"
android:orderInCategory="50"
tools:ignore="AppCompatResource"
tools:showAsAction="ifRoom"/>
清单:
<activity
android:configChanges="orientation|screenSize"
android:name=".MapsActivity"
android:uiOptions="splitActionBarWhenNarrow"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.ferenczandras.transportmures.HARTA" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
谢谢
答案 0 :(得分:1)
尝试使用 - &gt;工具:showAsAction = “总是”
<item android:id="@+id/action_search"
tools:ignore="AppCompatResource"
android:orderInCategory="50"
android:icon="@android:drawable/ic_menu_search"
android:title="Caută"
tools:showAsAction="always"/>
<item android:id="@+id/action_cagain"
android:icon="@drawable/ic_action_refresh"
android:title="Încearcă din nou"
android:orderInCategory="50"
tools:ignore="AppCompatResource"
tools:showAsAction="always"/>
答案 1 :(得分:0)
请尝试使用tools:showAsAction="ifRoom"
android:showAsAction="always"
答案 2 :(得分:0)
更改主题...默认的MAPACTIVITY THeme不会显示活动栏..要么完全从Manifest中的标签中删除它们,要么将其更改为显示操作栏的主题。
这应该记录得更好,但是这样做会显示菜单。