2

操作栏上有一个带有自定义图像的 ShareActionProvider 按钮。此外修改了 ShareActionProvider 代码(如何在分享操作提供程序附近隐藏分享操作(使用最多)图标?https: //gist.github.com/saulpower/10557956 )。在多部手机(Samsung Galaxy S3 - Android 4.1、Huawei G730-U10 - Android 4.2)上发生崩溃。

文件 ic_action_share.png 存在于文件夹 drawable-xxhdpi、drawable-xhdpi、drawable-hdpi、drawable-mdpi 中。为什么 Android 从 v4 文件夹请求此图像(java.lang.NumberFormatException: Invalid int: "res/drawable-xhdpi-v4/ic_action_share.png")?

堆:

android.view.InflateException: Binary XML file line #8: Error inflating class android.widget.ImageButton
at android.view.LayoutInflater.createView(LayoutInflater.java:613)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at com.android.internal.app.ActionBarImpl.setCustomView(ActionBarImpl.java:330)
...
Caused by: java.lang.NumberFormatException: Invalid int: "res/drawable-hdpi-v4/ic_action_share.png"
at java.lang.Integer.invalidInt(Integer.java:138)
at java.lang.Integer.parse(Integer.java:375)
at java.lang.Integer.parseInt(Integer.java:366)
at com.android.internal.util.XmlUtils.convertValueToInt(XmlUtils.java:123)
at android.content.res.TypedArray.getInt(TypedArray.java:260)
at android.widget.ImageView.<init>(ImageView.java:151)
at android.widget.ImageButton.<init>(ImageButton.java:87)
at android.widget.ImageButton.<init>(ImageButton.java:83)
java.lang.NumberFormatException: Invalid int: "res/drawable-xhdpi-v4/ic_action_share.png"
at java.lang.Integer.invalidInt(Integer.java:138)
at java.lang.Integer.parse(Integer.java:375)
at java.lang.Integer.parseInt(Integer.java:366)
at com.android.internal.util.XmlUtils.convertValueToInt(XmlUtils.java:123)
at android.content.res.TypedArray.getInt(TypedArray.java:254)
at android.view.View.<init>(View.java:3561)
at android.view.ViewGroup.<init>(ViewGroup.java:432)
at com.example.trace.CustomShareActionProvider.ActivityChooserView.<init>(Unknown Source)
at com.example.trace.CustomShareActionProvider.ActivityChooserView.<init>(Unknown Source)
at com.example.trace.CustomShareActionProvider.ActivityChooserView.<init>(Unknown Source)
at com.example.trace.CustomShareActionProvider.ShareActionProvider.onCreateActionView(Unknown Source)
at android.support.v4.view.j.onCreateActionView(Unknown Source)
at android.support.v7.internal.view.menu.y.onCreateActionView(Unknown Source)
at com.android.internal.view.menu.MenuItemImpl.getActionView(MenuItemImpl.java:580)
at android.support.v7.internal.view.menu.t.getActionView(Unknown Source)
at android.support.v4.view.y.a(Unknown Source)
at com.example.trace.p.a(Unknown Source)
at android.support.v4.app.Fragment.b(Unknown Source)
at android.support.v4.app.n.a(Unknown Source)
at android.support.v4.app.h.onCreatePanelMenu(Unknown Source)
at android.support.v7.a.g.a(Unknown Source)
at android.support.v7.a.m.a(Unknown Source)
at android.support.v7.a.g.onCreatePanelMenu(Unknown Source)
at android.support.v7.a.n.onCreatePanelMenu(Unknown Source)
at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:445)
at com.android.internal.policy.impl.PhoneWindow.invalidatePanelMenu(PhoneWindow.java:819)
at android.app.Activity.invalidateOptionsMenu(Activity.java:2690)
...

样式.xml

<style name="app_theme" parent="@style/Theme.AppCompat.Light">
    <!-- Support library compatibility -->
    <item name="actionBarWidgetTheme">@style/CustomShareIcon</item>
    ...
    <item name="android:actionBarWidgetTheme" tools:targetApi="14">@style/CustomShareIcon</item>
</style>

<style name="CustomShareIcon" parent="@style/Theme.AppCompat">
    <item name="actionModeShareDrawable">@drawable/ic_action_share</item>
    <item name="*android:actionModeShareDrawable">@drawable/ic_action_share</item>
</style>
4

1 回答 1

0

尝试这个

在您的文件夹中添加图像ic_action_share.pngres/drawable-hdpi-v4/

v-4 是第 4 版,因此它只自动访问 v-4 文件夹。

于 2014-12-09T06:08:19.427 回答