ShareActionProvider有分流动作条 [英] ShareActionProvider with a split ActionBar

查看:176
本文介绍了ShareActionProvider有分流动作条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了一个 ShareActionProvider ,并想借此拆分动作条的优势时,有没有在顶部足够的空间吧 - Android的:uiOptions =splitActionBarWhenNarrow

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="splitActionBarWhenNarrow".

行动工作正常时,动作条并不需要拆分:

The action works fine when the ActionBar does not need to split:

然而,当动作条确实需要分割时,ActionProvider似乎彻底打破了较低的动作条的布局。它填充下面的顶部和动作条本身没有出现在动作整个视口:

However when the ActionBar does need to split, the ActionProvider seems to break the lower ActionBar layout completely. It fills the entire viewport below the top ActionBar and the action itself does not appear:

有没有人能一起成功地使用这两项功能?

Has anyone been able to use these two features together successfully?

推荐答案

一些如何创建一个共享历史文件修复此问题

Some how creating a share history file fixes this issue

这可以固定使用一个自定义共享历史文件的应用程序安装。

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

例如。调用CreateShareHisotryFile()的应用程序创建()

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 = "<?xml version='1.0' encoding='UTF-8' standalone='yes' ?> "+
                 "<historical-records>" +
                  "<historical-record activity=\"com.google.android.apps.plus/com.google.android.libraries.social.gateway.GatewayActivity\" time=\"1426500217970\" weight=\"1.0\" />"+
            "</historical-records>";
    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());
    } 
}

然后在片段的onCreateOptionsMenu使用共享历史文件,我们刚刚创建....

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);
}

需要注意的是历史,记录需要在XML文件中@至少一个历史纪录的子元素

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

那么这一切都很好 享受.......

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

这篇关于ShareActionProvider有分流动作条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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