I want to customize ActionBar: change the color of the text, the background. I try to make it through styles, and it does not work. What's the catch? It works through the code, but not through xml.

<!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <!-- Customize your theme here. --> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> <item name="windowActionBar">false</item> <item name="windowNoTitle">true</item> <item name="android:actionBarStyle">@style/MyActionBar</item> </style> <style name="MyActionBar" parent="AppTheme"> <item name="android:background">@color/colorAccent</item> <item name="android:textColor">@color/colorWhite</item> </style> 

  • have the application registered in the manifest android: theme = "@ style / AppTheme"? - Android Android
  • Yes, it is registered by default! - Ivan Vovk
  • 2
    do you fundamentally do it through ActionBar? If not, there is a Toolbar, which is easier to implement and is not considered obsolete. - Jarvis_J
  • No, not fundamentally, can you show the working code? - Ivan Vovk

1 answer 1

You can do this (via ToolBar):

  <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="?android:actionBarSize" > <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> ...любые View </RelativeLayout> </android.support.v7.widget.Toolbar> 

accordingly, the ToolBar itself is customized like any widget. If necessary, you can add a style:

 xmlns:app="http://schemas.android.com/apk/res-auto" app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 

in styles you need to turn off ActionBar:

 <item name="windowActionBar">false</item> <item name="windowNoTitle">true</item> 

in code:

 ToolBar toolbar = (ToolBar) findViewById(R.id.tollbarId); toolbar.inflateMenu(R.menu.menuId); toolbar.setNavigationIcon(R.drawable.nav_con); 

...and so on.

  • Yes it does! - Ivan Vovk