本文介绍了无法强制行动提供共享行动提供的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是code我的活动

 进口android.app.Activity;
进口android.os.Bundle;
进口android.support.v7.widget.ShareActionProvider;
进口android.view.Menu;
进口android.view.MenuItem;

公共类MainActivity延伸活动{
私人ShareActionProvider shareAction;

@覆盖
保护无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.activity_main);
}

@覆盖
公共布尔onCreateOptionsMenu(功能菜单){
    //充气菜单;这增加了项目操作栏,如果它是present。
    。getMenuInflater()膨胀(R.menu.activity_main,菜单);
    菜单项项= menu.getItem(R.id.menu_settings);
    shareAction =(ShareActionProvider)item.getActionProvider();
    返回true;
}
 

}

存在的问题是,有一个铸造误差从ActionProvider到ShareActionProvider.Why就这样下面是activity_menu.xml

 <菜单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>

<项目
    机器人:ID =@ + ID / menu_settings
    机器人:orderInCategory =100
    机器人:showAsAction =总是
    机器人:标题=@字符串/ menu_settings
    机器人:actionProviderClass =android.widget.ShareActionProvider
    />

< /菜单>
 

解决方案

我有同样的问题,我已经找到了解决办法:

1)必须使用:

 <菜单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    的xmlns:BWQ =htt​​p://schemas.android.com/apk/res-auto>

    <项目
        机器人:ID =@ + ID / menu_share
        机器人:标题=@字符串/ menu_share
        BWQ:actionProviderClass =android.support.v7.widget.ShareActionProvider
        BWQ:showAsAction =总是/>
< /菜单>
 

2)和在Java中

 进口android.support.v7.widget.ShareActionProvider;
 

  //找到菜单项与ShareActionProvider
菜单项项= menu.findItem(R.id.menu_share);
//读取和存储ShareActionProvider
mShareActionProvider =(ShareActionProvider)MenuItemCompat.getActionProvider(项目);
 

Below is the code for my Activity

import android.app.Activity;
import android.os.Bundle;
import android.support.v7.widget.ShareActionProvider;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends Activity {
private ShareActionProvider shareAction;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_main, menu);
    MenuItem item = menu.getItem(R.id.menu_settings);
    shareAction = (ShareActionProvider) item.getActionProvider();
    return true;
}

}

The Problem is that there is a cast error from ActionProvider to ShareActionProvider.Why it is so below is activity_menu.xml

 <menu xmlns:android="http://schemas.android.com/apk/res/android" >

<item
    android:id="@+id/menu_settings"
    android:orderInCategory="100"
    android:showAsAction="always"
    android:title="@string/menu_settings"
    android:actionProviderClass="android.widget.ShareActionProvider"
    />

</menu>
解决方案

I had the same problem and I have found the solution:

1) You have to use:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:bwq="http://schemas.android.com/apk/res-auto" >

    <item
        android:id="@+id/menu_share"
        android:title="@string/menu_share"
        bwq:actionProviderClass="android.support.v7.widget.ShareActionProvider"
        bwq:showAsAction="always"/>
</menu>

2) and in Java

import android.support.v7.widget.ShareActionProvider;

and

// Locate MenuItem with ShareActionProvider
MenuItem item = menu.findItem(R.id.menu_share);
// Fetch and store ShareActionProvider
mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(item);

这篇关于无法强制行动提供共享行动提供的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 04:09