代码之家  ›  专栏  ›  技术社区  ›  M.N

动作栏为“灰色”/不可见颜色

  •  0
  • M.N  · 技术社区  · 7 年前

    首先,它没有显示,我按照说明添加了requestWindowFeature(Window.FEATURE\u ACTION\u BAR);在onCreate方法中,将显示动作栏,但其颜色为“灰色”/“不可见”。我仍然可以点击菜单项。你能告诉我如何使动作栏可见吗?谢谢 这是我的活动,是扩展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);
    

    这是我的风格,清单使用了下面的FMS主题:

    <!-- 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

    1 回复  |  直到 7 年前
        1
  •  0
  •   Alessio    7 年前

    让您的MapsActivity扩展AppCompatActivity(来自支持库),它本身扩展了FragmentActivity:

    public class MapsActivity extends AppCompatActivity {
    

    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>