操作栏为“灰色”/隐形颜色
Action Bar is in ''grey"/invisible color
我正在尝试为我的 activity 创建一个选项菜单。
首先,它没有显示,我按照说明添加了 requestWindowFeature(Window.FEATURE_ACTION_BAR);在 onCreate 方法中显示操作栏,但它是 'grey'/invisible 颜色。我仍然可以点击菜单项。你能告诉我如何使操作栏可见吗?谢谢。
这是我的 Activity,正在扩展 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>
Invisible actionbar image
让您的 MapsActivity 扩展 AppCompatActivity(来自支持库),它本身扩展了 FragmentActivity:
public class MapsActivity extends AppCompatActivity {
完成后,我建议您将工具栏设置为操作栏:
Toolbar toolbar = (Toolbar) findViewById(R.id.maps_activity_toolbar);
toolbar.setTitle("A title");
setSupportActionBar(toolbar);
然后您可以使用以下 2 个属性配置工具栏的主题:
<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>
我正在尝试为我的 activity 创建一个选项菜单。 首先,它没有显示,我按照说明添加了 requestWindowFeature(Window.FEATURE_ACTION_BAR);在 onCreate 方法中显示操作栏,但它是 'grey'/invisible 颜色。我仍然可以点击菜单项。你能告诉我如何使操作栏可见吗?谢谢。 这是我的 Activity,正在扩展 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>
Invisible actionbar image
让您的 MapsActivity 扩展 AppCompatActivity(来自支持库),它本身扩展了 FragmentActivity:
public class MapsActivity extends AppCompatActivity {
完成后,我建议您将工具栏设置为操作栏:
Toolbar toolbar = (Toolbar) findViewById(R.id.maps_activity_toolbar);
toolbar.setTitle("A title");
setSupportActionBar(toolbar);
然后您可以使用以下 2 个属性配置工具栏的主题:
<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>