ShareActionProvider theme theme is always dark

I am trying to add a share action to my toolbar. The toolbar should be orange (or transparent, as in this case) with white text and icons, so I use this view as a Toolbar :

 <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/toolbar" android:layout_height="wrap_content" android:layout_width="match_parent" android:minHeight="?attr/actionBarSize" app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" app:popupTheme="@style/ThemeOverlay.AppCompat.Light" tools:ignore="UnusedAttribute" /> 

Also, my app theme ad looks like this:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

No matter how I change the style, this is what I get:

enter image description here

How to convince ShareActionProvider to get a Light theme?

+5
source share
2 answers

my solution is based on v7 support library, toolBar, ActionBarActivity, Android Studio

1- uninstall app:popupTheme="@style/ThemeOverlay.AppCompat.Light"

2- make sure your base theme is Theme.AppCompat.Light.NoActionBar

3- go to the source code ShareActionProvider by typing "ShareActionProvider" anywhere in your code, then import v7, then hover over it (ctrl + left click)

4- copy the code into it and paste it into a new java file in the project directory

5 go to your own ShareActionProvider file and delete this import if you have import android.support.v7.appcompat.R

6- specify your own icon, because by default black Drawable myDrawable = mContext.getResources().getDrawable(R.drawable.ic_share); activityChooserView.setExpandActivityOverflowButtonDrawable(myDrawable); Drawable myDrawable = mContext.getResources().getDrawable(R.drawable.ic_share); activityChooserView.setExpandActivityOverflowButtonDrawable(myDrawable);

7- go to your business and delete the import you made in step 3 (to use your own file)

8- go to your onCreateOptionsMenu, it should be something like this:

 @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_main, menu); MenuItem item = menu.findItem(R.id.menu_item_share); mShareActionProvider = new ShareActionProvider(MainActivity.this); MenuItemCompat.setActionProvider(item , mShareActionProvider); Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.putExtra(Intent.EXTRA_TEXT, "Hello World"); shareIntent.setType("text/plain"); mShareActionProvider.setShareIntent(shareIntent); return true; } 

9- last step - do not forget to change your menu.xml

 app:actionProviderClass= "com.yourPackageName.ShareActionProvider" /> 
+3
source

This is what I did and it worked. I wanted a white background in ShareActionProvider , while the text was black

 <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" app:theme="@style/MainTheme" app:layout_collapseMode="pin"/> 

My theme

  <style name="MainTheme" parent="Theme.AppCompat.Light.NoActionBar"> <item name="colorPrimary">@color/md_white_1000</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> <item name="android:textColorPrimary">#ffffff</item> <item name="android:textColorSecondary">#ffffff</item> <item name="android:textColor">@color/md_black_1000</item> <item name="listPopupWindowStyle">@style/PopupListStyle</item> </style> <style name="PopupListStyle" parent="@style/Widget.AppCompat.Light.ListPopupWindow"> <item name="android:popupBackground">#ffffff</item> </style> 
+1
source

All Articles