ShareActionProvider with a split ActionBar

后端 未结 3 1677
悲&欢浪女
悲&欢浪女 2021-02-18 21:30

I\'m using a ShareActionProvider and would like to take advantage of the split ActionBar when there isn\'t enough room for it at the top - android:uiOptions=

3条回答
  •  太阳男子
    2021-02-18 22:01

    Some how creating a share history file fixes this issue

    this can be fixed by using a custom share history file on app install.

    e.g. call CreateShareHisotryFile() on App Create()

    public class YourBrokenAPP extends Application {
    
      public static SHARE_HISTORY_FILE_NAME = "c_share_hist.xml";
    
     @Override
     public void onCreate() {
         super.onCreate();  
         CreateShareHisotryFile(); 
     }
    
     private void CreateShareHisotryFile() {
    
        String data = " "+
                     "" +
                      ""+
                "";
        try {
            OutputStreamWriter outputStreamWriter = new     OutputStreamWriter(openFileOutput(SHARE_HISTORY_FILE_NAME, Context.MODE_PRIVATE));
             outputStreamWriter.write(data);
            outputStreamWriter.close();
        }
        catch (IOException e) {
            Log.e("Exception", "File write failed: " + e.toString());
        } 
    }
    

    then in the fragment's onCreateOptionsMenu use share history file we just created ....

     @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
         inflater.inflate(R.menu.main, menu);
    
      // Set up ShareActionProvider's default share intent
        MenuItem shareItem = menu.findItem(R.id.action_share);
        mShareActionProvider = (ShareActionProvider)
               MenuItemCompat.getActionProvider(shareItem);
        mShareActionProvider.setShareHistoryFileName(c_share_hist.xml);
    }
    

    Note that historical-records needs @ least one historical-record child element in the xml file

    then it's all good ENJOY.......

提交回复
热议问题