Created
September 16, 2018 10:31
-
-
Save foxanna/1d2908e8a2b5963155695912fc07ca7e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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