Skip to content

Instantly share code, notes, and snippets.

@foxanna
Created September 16, 2018 10:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save foxanna/1d2908e8a2b5963155695912fc07ca7e to your computer and use it in GitHub Desktop.
Save foxanna/1d2908e8a2b5963155695912fc07ca7e to your computer and use it in GitHub Desktop.
[assembly: ExportRenderer(typeof(SelectableLabel), typeof(SelectableLabelRenderer))]
namespace <project>.Droid.Controls
{
public class SelectableLabelRenderer : EditorRenderer
{
public SelectableLabelRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<Editor> e)
{
base.OnElementChanged(e);
if (Control == null)
return;
Control.Background = null;
Control.SetPadding(0, 0, 0, 0);
Control.ShowSoftInputOnFocus = false;
Control.SetTextIsSelectable(true);
Control.CustomSelectionActionModeCallback = new CustomSelectionActionModeCallback();
Control.CustomInsertionActionModeCallback = new CustomInsertionActionModeCallback();
}
private class CustomInsertionActionModeCallback : Java.Lang.Object, ActionMode.ICallback
{
public bool OnCreateActionMode(ActionMode mode, IMenu menu) => false;
public bool OnActionItemClicked(ActionMode m, IMenuItem i) => false;
public bool OnPrepareActionMode(ActionMode mode, IMenu menu) => true;
public void OnDestroyActionMode(ActionMode mode) { }
}
private class CustomSelectionActionModeCallback : Java.Lang.Object, ActionMode.ICallback
{
private const int CopyId = Android.Resource.Id.Copy;
public bool OnActionItemClicked(ActionMode m, IMenuItem i) => false;
public bool OnCreateActionMode(ActionMode mode, IMenu menu) => true;
public void OnDestroyActionMode(ActionMode mode) { }
public bool OnPrepareActionMode(ActionMode mode, IMenu menu)
{
try
{
var copyItem = menu.FindItem(CopyId);
var title = copyItem.TitleFormatted;
menu.Clear();
menu.Add(0, CopyId, 0, title);
}
catch
{
// ignored
}
return true;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment