2018年4月5日 星期四

Change the menu style on ActionBar

Reference:

http://www.itstrike.cn/Question/c9ee24fa-9e1a-4154-a304-1fd41d418561.html

Code snippet:

1. Background

AndroidManifest.xml
<application    ......
    android:theme="@style/AppTheme">

style.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">   
    <!-- Customize actionbar overflow menu-->    <item name="actionOverflowMenuStyle">@style/My.Widget.Material.Light.PopupMenu.Overflow</item>    
</style>

<style name="My.Widget.Material.Light.PopupMenu.Overflow" parent="android:Widget.Material.Light.PopupMenu.Overflow">
    <item name="android:popupBackground">@drawable/my_popup_background_material</item>
</style>


drawable/my_popup_background_material.xml
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"       android:shape="rectangle">
    <corners            android:radius="12dp" />
    <solid            android:color="@color/action_bar_color" />
</shape>

2. List choice background
activity_layout.xml
......
<android.support.v7.widget.Toolbar    android:id="@+id/tool_bar"    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:background="@color/action_bar_color"    android:theme="@style/AppTheme.AppBarOverlay"    app:contentInsetStartWithNavigation="0dp"    app:popupTheme="@style/AppTheme.PopupOverlay" >

style.xml
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light">
    <item name="android:textColor">@color/list_item_title</item>
    <item name="android:textSize">18sp</item>
    <item name="android:textStyle">normal</item>
    <item name="android:listChoiceBackgroundIndicator">@drawable/my_list_choice_background_material</item>
</style>

drawable/my_list_choice_background_material.xml
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"        android:color="@color/list_highlight_material">
    <item>
        <shape android:shape="rectangle">
            <corners android:radius="12dp"/>
            <solid android:color="@color/action_bar_color" />
        </shape>
    </item>
</ripple>

沒有留言: