首先要在menu菜单里做好menu
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/menu1"
android:title="我是添加"/>
<item android:id="@+id/menu2"
android:title="我是添加"/>
</menu>
在活动也制作menu,以及设置它的toast
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu1,menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item){
switch (item.getItemId()){
case R.id.menu1:
Toast.makeText(this,"你想添加",Toast.LENGTH_SHORT).show();
break;
case R.id.menu2:
Toast.makeText(this,"你想删除",Toast.LENGTH_SHORT).show();
break;
default:
}
return true;
这是平时设置的toast
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(ToastActivity.this,"我被点击了",Toast.LENGTH_SHORT).show();
}
按压效果的实现press;
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/science"/>
<item android:drawable="@drawable/teacher"/>
</selector>