0

I am trying to setup a tooltip using a OnCreateOptionsMenu, however I am getting an error when trying to setText(text).

CODE:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.puzzle_tips, menu);

    SpannableString text = new SpannableString("TOP TIP:\nShake screen to reshuffle puzzle");
    text.setSpan(new ForegroundColorSpan(Color.RED), 0, 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    Drawable d = ContextCompat.getDrawable(getBaseContext(), R.drawable.tips_icon);
    d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
    ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BASELINE);
    text.setSpan(span, 31, 32, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);

    MenuItem menuItem = menu.findItem(R.id.menuPuzzleTips);
    Tooltip.Builder builder = new Tooltip.Builder(menuItem)
        .setCornerRadius(10f)
        .setGravity(Gravity.BOTTOM)
        .setText(text);
    builder.show();

    return super.onCreateOptionsMenu(menu);
}

ERROR:

error: no suitable method found for setText(SpannableString)
method Builder.setText(int) is not applicable
(argument mismatch; SpannableString cannot be converted to int)
method Builder.setText(String) is not applicable
(argument mismatch; SpannableString cannot be converted to String)
David G
  • 325
  • 1
  • 3
  • 15
  • Possible duplicate of [Spannable String Error](https://stackoverflow.com/questions/18033479/spannable-string-error) – Mr. Roshan Jul 09 '18 at 12:14
  • 1
    i think spannable string apply into text view not menu item. if you want apply some style in menu item then it apply into menu item.xml file. –  Jul 09 '18 at 12:32
  • what's this Tooltip Builder API? Obviously it does not accept Spannables. – Flo We Jul 09 '18 at 13:55
  • Is there anyway i could write this without the Spannables? – David G Jul 09 '18 at 14:59

0 Answers0