Edittext That Make Selection On Long Click But Do Not Show Context Menu?
Solution 1:
you want to get rid of the ActionMode? and create your own??
you can override this and get notified when the default is about to be displayed
@OverridepublicvoidonSupportActionModeStarted(ActionMode mode) {
super.onSupportActionModeStarted(mode);
//you can add your custom ui here
mode.setCustomView(....);// it takes a view
}
if you want to close it then you call mode.finish();
you can call it there to close if or finish it if you do not need it.
when it is about to die it calls this onSupportActionModeFinished(ActionMode mode)` the methods i have stated are for the support libraries, hope you know that.
The rest is cheese
Solution 2:
Finally I have sorted this out. This solution perfectly works for me. First of all, you need to create the context menu background as follows
menuback.xml
<?xml version="1.0" encoding="utf-8"?><selectorxmlns:android="http://schemas.android.com/apk/res/android"><item><shapeandroid:shape="rectangle"><solidandroid:color="@android:color/transparent"/></shape></item></selector>
Then Create your Custom Menu as follows
mymenu.xml
<?xml version="1.0" encoding="utf-8"?><menuxmlns:android="http://schemas.android.com/apk/res/android"><itemandroid:id="@+id/m"android:title=" " ></item></menu>
Now add the following lines on your
styles.xml
<resources><!-- Base application theme. --><stylename="AppTheme"parent="Theme.AppCompat.Light.DarkActionBar"><!-- Customize your theme here. --><itemname="colorPrimary">@color/colorPrimary</item><itemname="colorPrimaryDark">@color/colorPrimaryDark</item><itemname="colorAccent">@color/colorAccent</item><itemname="windowActionModeOverlay">true</item><itemname="actionModeBackground">@drawable/menuback</item><itemname="actionBarSize">1dp</item><itemname="android:actionModeCloseDrawable">@android:color/transparent</item></style></resources>
And Finally set elevation of the actionbar to 0 and implement the ActionMode.CallBack as follows
EditText editText=findViewById(R.id.ed);
getSupportActionBar().setElevation(0);
editText.setCustomSelectionActionModeCallback(newActionMode.Callback() {
@OverridepublicbooleanonCreateActionMode(ActionMode mode, Menu menu) {
mode.getMenu().clear();
MenuInflater inflater=mode.getMenuInflater();
inflater.inflate(R.menu.mymenu,menu);
returntrue;
}
@OverridepublicbooleanonPrepareActionMode(ActionMode mode, Menu menu) {
returnfalse;
}
@OverridepublicbooleanonActionItemClicked(ActionMode mode, MenuItem item) {
returnfalse;
}
@OverridepublicvoidonDestroyActionMode(ActionMode mode) {
}
});
Ta...da... Here is the Final Result
Post a Comment for "Edittext That Make Selection On Long Click But Do Not Show Context Menu?"