2017-02-13 44 views
1

我要重写程序兼容性动作条的风格,我这样做:改变动作条风格的Android

<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" 
    /> 

您的帮助将不胜感激,谢谢

+0

style =“style/MyActionBar” –

+0

您需要使样式为NoActionBar。然后你需要一个AppBarLayout –

+0

参考这个SO问题[如何设置自定义操作栏颜色样式](http://stackoverflow.com/questions/18288402/how-to-set-custom-actionbar-color -样式) –

回答

0

设置活动主题,以这种风格

<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" />