1-) Android - CONTEXT MENU KULLANIMI ÜZERİNE BASIK TUTTUĞUMUZDA ÇIKAR(YENİ VERSİYON)
1-)itemler = 1 adet TextView
2-)sol taraftan menu oluştur ismi contex_menu.xml içi
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity">
<item
android:id="@+id/sil"
android:orderInCategory="0"
android:title="sil"
android:icon="@android:drawable/ic_menu_delete"
app:showAsAction="always"
/>
<item
android:id="@+id/duzenle"
android:orderInCategory="0"
android:title="düzenle"
android:icon="@android:drawable/ic_menu_edit"
app:showAsAction="always"
/></menu>
3-)OnCreatın bulundugu bolgede aşşagıda
public class MainActivity extends AppCompatActivity {
private ActionMode actionMode;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView vv = (TextView) findViewById(R.id.textView);
vv.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
if (actionMode != null) {//contex menu warsa tekrar olusturmaması için
return false; }
menu_class cagir = new menu_class();
actionMode = startActionMode(cagir);
v.setSelected(true);
return true; } }); }
class menu_class implements ActionMode.Callback {
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
mode.getMenuInflater().inflate(R.menu.menu_contex, menu);
return true; }
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
//action mode gosterilmeden once yapılması gereken ıslem bunu boşver
return false; }
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
switch (item.getItemId()) {
case R.id.sil:
Toast.makeText(getApplicationContext(), "silindi ", Toast.LENGTH_SHORT).show();
mode.finish();
return true;
case R.id.duzenle:
Toast.makeText(getApplicationContext(), "duzenle ", Toast.LENGTH_SHORT).show();
mode.finish();
return true;
default:
return false; } }
@Override
public void onDestroyActionMode(ActionMode mode) {
actionMode = null; } }}