我正在尝试使用OnCreateOptionsMenu设置工具提示,但是在尝试设置setText(text)时出现错误。
代码:
@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: 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)