微信中长按弹出菜单(1) 没有实现功能

微信中长按弹出菜单(1) 没有实现功能_第1张图片

MainActivity:

package com.example.menumeration;

import android.app.Activity;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		TextView text=(TextView) findViewById(R.id.text);
		text.setOnCreateContextMenuListener(this);
	}
	
	@Override
	public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
		menu.add(0, 1001, 0, "标为未读");
		menu.add(0, 1002, 1, "删除聊天");
		menu.add(0, 1003, 2, "设为置顶");
		
		super.onCreateContextMenu(menu, v, menuInfo);
	}
	
	@Override
	public boolean onContextItemSelected(MenuItem item) {
		
			Toast.makeText(this,item.getTitle(), Toast.LENGTH_LONG).show();
		
		return super.onContextItemSelected(item);
	}
}


acitivity:

只有一个普通的TextView。



    


 

你可能感兴趣的:(长按弹出菜单)