ShareActionProvider menu style

I have this menu when the user clicks on the ShareActionProvider: 在这里输入图像描述

How can I change its background color. I suppose I have to style it but I cannot find anywhere how.


You might want to take a look at the source code, if there is no documentation on how to apply a style. I haven't actually tried to style the ShareActionProvider, but I got quite some clues from the code:

  • ShareActionProvider.java is probably responsible in the first place
  • ActivityChooserView.java looks like the used view class which leads to ...
  • abc_activity_chooser_view.xml is most likely the used view, which has ?attr/activityChooserViewStyle applied as the style reference
  • looking into themes.xml yields in line 75:

    <item name="activityChooserViewStyle">@style/Widget.AppCompat.ActivityChooserView</item>
    
  • Would love to hear if this works, as I might be in the same situation soon ;)


    So, what I did to style it was edit our styles.xml.

    <!-- ACTION BAR -->
    <style name="ToolbarTheme">
        <item name="android:textColorPrimary">#fff</item>
        <item name="colorControlNormal">#fff</item>
        <item name="colorControlHighlight">#3fff</item>
        <item name="android:listPopupWindowStyle">@style/ToolbarPopupListStyle</item>
        <item name="listPopupWindowStyle">@style/ToolbarPopupListStyle</item>
        <item name="android:textAppearanceLargePopupMenu">@style/PopupMenuTextAppearance</item>
        <item name="textAppearanceLargePopupMenu">@style/PopupMenuTextAppearance</item>
    </style>
    <style name="ToolbarStyle">
        <item name="android:background">?colorPrimary</item>
        <item name="android:titleTextAppearance">@style/collapsedToolbarText</item>
        <item name="titleTextAppearance">@style/collapsedToolbarText</item>
    </style>
    
    <style name="ToolbarPopupListStyle">
        <item name="android:popupBackground">#00ff00</item>
    </style>
    <style name="PopupMenuTextAppearance" parent="android:TextAppearance.Small">
        <item name="android:textColor">#ff0000</item>
    </style>
    

    Of course, these styles have to be referenced in the layout file where Toolbar is referenced:

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar_toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@android:color/transparent"
        app:layout_collapseMode="pin"
        app:theme="@style/ToolbarTheme"
        style="@style/ToolbarStyle"/>
    

    I have the weird feeling, though, that styles should have a parent style. But it works out like this.

    Thanks to @Brian who pointed me in the right direction.

    链接地址: http://www.djcxy.com/p/15858.html

    上一篇: CocoaPods podspec lint失败

    下一篇: ShareActionProvider菜单样式