与其他图标相比,AppCompat ShareActionProvider图标太大 [英] AppCompat ShareActionProvider icon is too big compared to other icons

查看:77
本文介绍了与其他图标相比,AppCompat ShareActionProvider图标太大的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将ActionBarSherlock更改为AppCompat v7.我已经做了使它正常工作所需的所有更改,但是共享图标(正在使用ShareActionProvider)发生了一些奇怪的事情.与其他图标相比,共享图标太大.我也使用支持库进行搜索,它的大小正确.问题仅在于共享图标.

I changed the ActionBarSherlock to AppCompat v7. I already did all the changes that are needed to make it work, but something weird is happening with share icon (which is using ShareActionProvider). The share icon is too big compared to other icons. I also use the support library for my search, and its size is correct. The problem is just with the share icon.

my_menu.xml:

my_menu.xml:

    <menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:moblee="http://schemas.android.com/apk/res-auto" >
    <item
        android:id="@+id/menu_share"
        android:padding="10dp"
        android:title="@string/menu_share"
        moblee:actionProviderClass="android.support.v7.widget.ShareActionProvider"
        moblee:showAsAction="always"/>
    <item
        android:id="@+id/menu_search"
        android:title="@string/menu_search"
        moblee:actionViewClass="android.support.v7.widget.SearchView"
        moblee:showAsAction="always"/>
</menu>

片段:

public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.my_menu, menu);
    MenuItem item = menu.findItem(R.id.menu_share);
    ShareActionProvider shareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(item);
    shareActionProvider.setShareIntent(getDefaultShareIntent());
}

styles.xml

styles.xml

<style name="Theme.Custom" parent="Theme.AppCompat.Light.DarkActionBar">

        <item name="colorPrimary">@color/main_bar</item>
        <item name="colorPrimaryDark">@color/main_bar</item>
        <item name="actionBarItemBackground">@drawable/selectable_background_custom</item>
        <item name="selectableItemBackground">@drawable/selectable_background_custom</item>

        <item name="android:windowBackground">@color/background</item>

        <item name="android:popupMenuStyle">@style/PopupMenu.Custom</item>
        <item name="android:dropDownListViewStyle">@style/DropDownListView.Custom</item>
        <item name="android:actionDropDownStyle">@style/DropDownNav.Custom</item>
        <item name="android:actionModeBackground">@drawable/cab_background_top_custom</item>
        <item name="android:actionModeSplitBackground">@drawable/cab_background_bottom_custom</item>
        <item name="android:actionModeCloseButtonStyle">@style/ActionButton.CloseMode.Custom</item>

        <item name="vpiTabPageIndicatorStyle">@style/VpiTabPageIndicator.Custom</item>
        <item name="android:editTextBackground">@drawable/edit_text_holo_light</item>
        <item name="android:listChoiceBackgroundIndicator">@drawable/list_selector_holo_light</item>
        <item name="android:activatedBackgroundIndicator">@drawable/activated_background_holo_light</item>
        <item name="android:fastScrollThumbDrawable">@drawable/fastscroll_thumb_holo</item>
        <item name="android:listViewStyle">@style/ListViewCustom</item>
        <item name="android:gridViewStyle">@style/GridViewCustom</item>
        <item name="android:textViewStyle">@style/TextViewCustom</item>
        <item name="android:checkboxStyle">@style/CheckBoxCustom</item>
    </style>

    <style name="PopupMenu.Custom" parent="@style/Widget.AppCompat.ListPopupWindow">
        <item name="android:popupBackground">@drawable/menu_dropdown_panel_custom</item>
    </style>

    <style name="DropDownListView.Custom" parent="@style/Widget.AppCompat.ListView.DropDown">
        <item name="android:listSelector">@drawable/selectable_background_custom</item>
    </style>

    <style name="Theme.Custom.Widget" parent="@style/Theme.AppCompat">
        <item name="android:popupMenuStyle">@style/PopupMenu.Custom</item>
        <item name="android:dropDownListViewStyle">@style/DropDownListView.Custom</item>
    </style>

推荐答案

我最终使用的解决方案不再使用ShareContentProvider,而是使用Intent.createChooser().进行这些更改非常简单,它会打开新的共享对话框,如下所示:

The solution I ended up using is not use ShareContentProvider anymore, instead i'm using Intent.createChooser(). It was pretty simple to do these changes and it opens the new share dialog, as shown below:

操作栏中的共享图标:

对话框:

menu.xml

<item
    android:id="@+id/menu_share"
    android:checkable="true"
    android:icon="@drawable/ic_menu_share"
    myapp:showAsAction="always"
    android:title="@string/menu_share"/>

片段类:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int itemId = item.getItemId();
    if (itemId == R.id.menu_share) {
        showShareDialog();
    }
        return super.onOptionsItemSelected(item);
}

private void showShareDialog(String message) {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEND);
    intent.setType("text/plain");

    intent.putExtra(Intent.EXTRA_SUBJECT, mTitle);
    intent.putExtra(Intent.EXTRA_TEXT, mMessage);

    startActivity(Intent.createChooser(intent, getString(R.string.menu_share)));
}

这篇关于与其他图标相比,AppCompat ShareActionProvider图标太大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆