Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Toolbar ShareActionProvider theme is always dark

I'm trying to add share action to my toolbar. Toolbar is supposed to be orange (or transparent like in this case) with white text and icons, so I'm using this view as 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, this is how my app theme declaration looks like:

<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 do I convince ShareActionProvider to get Light theme?

like image 301
Jacek Kwiecień Avatar asked Apr 21 '15 08:04

Jacek Kwiecień


2 Answers

This is what i did and it worked. i wanted a white background in ShareActionProvider with it text being 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>
like image 83
Edijae Crusar Avatar answered Oct 29 '22 17:10

Edijae Crusar


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

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

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

3- go to original code of ShareActionProvider by typing "ShareActionProvider" anywhere in your code then import the v7 one then aim your mouse on it then (ctrl + left click)

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

5- go to your own ShareActionProvider and remove this import if you have it import android.support.v7.appcompat.R

6- provide your own share icon because the default one is black Drawable myDrawable = mContext.getResources().getDrawable(R.drawable.ic_share); activityChooserView.setExpandActivityOverflowButtonDrawable(myDrawable);

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

8- go to your onCreateOptionsMenu it should be 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- the last step is don't forget to edit your menu.xml

app:actionProviderClass=
            "com.yourPackageName.ShareActionProvider" />
like image 45
Mohamad Bdour Avatar answered Oct 29 '22 16:10

Mohamad Bdour