Skip to content

Instantly share code, notes, and snippets.

View luck-alex13's full-sized avatar

Alexandr Novikov luck-alex13

  • Russia
View GitHub Profile
@luck-alex13
luck-alex13 / SomeClass
Last active March 1, 2018 03:41
Default html and links support in TextView
textView.setText(fromHtml(text));
textView.setMovementMethod(LinkMovementMethod.getInstance());
public static Spanned fromHtml(String html) {
Spanned result;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
result = Html.fromHtml(html, Html.FROM_HTML_MODE_LEGACY);
} else {
result = Html.fromHtml(html);
@luck-alex13
luck-alex13 / PopupMenu
Created February 19, 2018 07:14
Show Android Popup Menu
public static PopupMenu buildPopupMenu(View view, int menuRes) {
PopupMenu popup = new PopupMenu(view.getContext(), view);
popup.inflate(menuRes);
return popup;
}
public static PopupMenu showPopupMenuOn(View view, int menuRes, PopupMenu.OnMenuItemClickListener listener){
PopupMenu menu = buildPopupMenu(view, menuRes);
menu.setOnMenuItemClickListener(listener);
menu.show();