Setting a custom share icon on Actionbar ShareActionProvider

前端 未结 5 576
情书的邮戳
情书的邮戳 2021-01-01 20:28

I\'m trying to set the icon ShareActionProvider, need a solid white one instead of the semi transparent white one.

However setting in share_menu.xml and code doesn

5条回答
  •  北荒
    北荒 (楼主)
    2021-01-01 20:42

    UPDATE: Forget about the TRICKY way below, just sub-class ShareActionProvider, return null in onCreateActionView Method, and provide your own icon in menu.xml file, everything will be fine

    ===========================

    I found a very tricky but none-ActionBarSherlock-specific way:

    1. Sub-class ShareActionProvider, with just a little tweak:

      @Override
      public View onCreateActionView() {
          View target = super.onCreateActionView();
          ViewGroup viewGroup = (ViewGroup) LayoutInflater.from(context).inflate(R.layout.actionbutton_share, null);
          ImageView overlay = (ImageView) viewGroup.findViewById(R.id.overlay);
          ViewGroup container = (ViewGroup) viewGroup.findViewById(R.id.container);
          container.addView(target);
          container.getLayoutParams().width = overlay.getLayoutParams().width;
          container.getLayoutParams().height = overlay.getLayoutParams().height;
          return viewGroup;
      }
      
    2. Create a layout file (R.layout.actionbutton_share), which place the original view at top but transparent to user (Note the "android:alpha=0" part) :

      
      
      
          
      
          
      
      
      
    3. Use the hacked ShareActionProvider in your menu.xml file

提交回复
热议问题