Last active
November 12, 2015 10:57
-
-
Save tseglevskiy/87227454f9b57ea69399 to your computer and use it in GitHub Desktop.
Text Selection Demo
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
// floating menu on long click | |
callback = new AcCallback(); | |
textView1.setOnLongClickListener(new View.OnLongClickListener() { | |
@Override | |
public boolean onLongClick(View v) { | |
if (actionMode != null) { | |
return false; | |
} | |
// old startActionMode(callback) | |
// == new startActionMode(callback, ActionMode.TYPE_PRIMARY); | |
actionMode = startActionMode(callback, ActionMode.TYPE_FLOATING); | |
v.setSelected(true); | |
return true; | |
} | |
}); |
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
// selection menu! | |
callback = new AcCallback(); | |
textView2.setTextIsSelectable(true); | |
textView2.setCustomSelectionActionModeCallback(callback); | |
editText.setCustomSelectionActionModeCallback(callback); |
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
// callback | |
public class AcCallback extends ActionMode.Callback2 { | |
@Override | |
public boolean onCreateActionMode(ActionMode mode, Menu menu) { | |
mode.getMenuInflater().inflate(R.menu.context_menu, menu); | |
return true; | |
} | |
@Override | |
public boolean onPrepareActionMode(ActionMode mode, Menu menu) { | |
return true; | |
} | |
@Override | |
public boolean onActionItemClicked(ActionMode mode, MenuItem item) { | |
switch (item.getItemId()) { | |
case R.id.action_one: | |
Toast.makeText(MainActivity.this, "One!", Toast.LENGTH_SHORT).show(); | |
mode.finish(); // Action picked, so close the CAB | |
return true; | |
case R.id.action_two: | |
Toast.makeText(MainActivity.this, "Two!", Toast.LENGTH_SHORT).show(); | |
mode.finish(); // Action picked, so close the CAB | |
return true; | |
default: | |
return false; | |
} | |
} | |
@Override | |
public void onDestroyActionMode(ActionMode mode) { | |
actionMode = null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment