@Override
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu; this adds items to the action bar if it is present.
//getMenuInflater().inflate(R.menu.main, menu);
menu.add(0,1,1,"设置").setIcon(R.drawable.setting);
menu.add(0,3,3,"设置").setIcon(R.drawable.setting);
menu.add(0,2,2,"下载").setIcon(R.drawable.download);
}
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
// TODO Auto-generated method stub
if (item.getGroupId() == 0 &&item.getItemId() == 1)
{
Intent intent = new Intent(this, SecondActivity.class);
startActivity(intent);
}
else
{
Toast.makeText(this, item.getTitle(), Toast.LENGTH_SHORT).show();
}
return super.onOptionsItemSelected(item);
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo)
{
menu.add(0, 1, 0, "红色背景");
menu.add(0, 2, 0, "绿色背景");
menu.add(1, 3, 0, "白色背景");
// TODO Auto-generated method stub
super.onCreateContextMenu(menu, v, menuInfo);
}
@Override
public boolean onContextItemSelected(MenuItem item)
{
// TODO Auto-generated method stub
switch(item.getItemId()) {
case 1:
myText.setBackgroundColor(Color.RED);
break;
case 2:
myText.setBackgroundColor(Color.GREEN);
break;
case 3:
myText.setBackgroundColor(Color.WHITE);
break;
}
return true;
}
private TextView myText;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myText = (TextView)findViewById(R.id.mytext);
registerForContextMenu(myText);
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu; this adds items to the action bar if it is present.
SubMenu subMenu = menu.addSubMenu(0, 4, 4, "登录/注册");
subMenu.add(1, 1, 1, "登录");
subMenu.add(1, 2, 2, "注册");
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
if(item.getTitle().equals("登录"))
{
Log.e("action:","点击了 注册/登录");
}
return super.onOptionsItemSelected(item);
}
<menu xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@+id/action_edit" android:orderInCategory="100" android:showAsAction="never" android:title="edit"/> <item android:id="@+id/action_share" android:orderInCategory="100" android:showAsAction="never" android:title="popup"/> </menu>
public void showPopuMenu(View v)
{
PopupMenu popup = new PopupMenu(MainActivity.this, v);
MenuInflater inflater = popup.getMenuInflater();
inflater.inflate(R.menu.popup, popup.getMenu());
popup.show();
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有