在 android 中更改操作栏样式

change actionbar style in android

我想覆盖 appcompat 操作栏样式,我这样做:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>

    <item name="android:actionBarStyle">@style/MyActionBar</item>
</style>

 <style name="MyActionBar" parent="android:style/Theme.Holo.Light.DarkActionBar">
    <item name="android:background">@android:color/black</item>

但这不适用于该元素, 这是一个 XML 元素:

  <android.support.v7.widget.Toolbar
    android:id="@+id/toolbar_bottom"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    />

非常感谢您的帮助,谢谢

使用local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"

有关详细信息,请参阅 https://dzone.com/articles/getting-started-with-android-app-and-material-desi

将 Activity 主题设置为此样式

 <style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

在您的 xml 中,您的工具栏应该在 AppBarLayout

中创建
  <android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/MyTheme"
    app:elevation="0dp"
    app:popupTheme="@style/AppTheme.PopupOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:theme="@style/MyTheme"
        app:popupTheme="@style/AppTheme.PopupOverlay"/>


</android.support.design.widget.AppBarLayout>

MyTheme 应该有父主题 ThemeOverlay.AppCompat.Dark.ActionBar

  <style name="MyTheme" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
//customize toolbar here`</style>

`

 <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />