我正在尝试为我的活动创建一个选项菜单。首先,它没有显示,我按照说明在onCreate方法中添加了requestWindowFeature(Window.FEATURE_ACTION_BAR);,操作栏正在显示,但它是灰色的/不可见的颜色。我仍然可以点击菜单项。您能告诉我如何使操作栏可见吗?谢谢。这是我的活动,扩展FragmentActivity是必须的,因为我的地图片段需要它:
public class MapsActivity extends FragmentActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_ACTION_BAR);
setContentView(R.layout.activity_map);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);}
这是我的风格,清单使用了下面的FMSTheme:
<!-- FMS theme -->
<style name="FMSTheme" parent="AppBaseTheme">
<item name="android:windowNoTitle">false</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowActionModeOverlay">false</item>
</style>发布于 2017-07-04 11:20:45
让您的MapsActivity扩展AppCompatActivity (来自支持库),它本身扩展了一个FragmentActivity:
public class MapsActivity extends AppCompatActivity {一旦你这样做了,我建议你将一个工具栏设置为一个actionbar:
Toolbar toolbar = (Toolbar) findViewById(R.id.maps_activity_toolbar);
toolbar.setTitle("A title");
setSupportActionBar(toolbar);然后,您可以使用以下两个属性配置工具栏的主题:
<android.support.v7.widget.Toolbar
android:theme="@style/MyToolbarTheme"
app:popupTheme="@style/MyToolbarPopupTheme">你可以根据自己的意愿进行定制,例如,你可以有一个深色的动作栏主题和一个浅色菜单主题(反之亦然):
<!-- the theme of the toolbar on MapsActivity -->
<style name="ToolbarTheme" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<!-- Customize your theme here. -->
<!-- default text color and menu dots -->
<item name="android:textColorPrimary">@color/my_toolbar_text_color</item>
</style>
<!-- the theme of the menu which opens from ActionBar on MapsActivity -->
<style name="MyToolbarPopupTheme" parent="ThemeOverlay.AppCompat.Light">
<!-- Customize your theme here. -->
</style>https://stackoverflow.com/questions/44896246
复制相似问题