首页 > 其他分享 >通过xml加载菜单Menus

通过xml加载菜单Menus

时间:2023-06-22 22:04:36浏览次数:29  
标签:xml 菜单 source menu Menus tag Menu print view

<MENU xmlns:android="http://schemas.android.com/apk/res/android">
 <GROUP android:id="@+id/myGroup">
  <ITEM android:id="@+id/New" android:title="New" android:orderInCategory="0"></ITEM>
  <ITEM android:id="@+id/Save" android:title="@string/save" android:orderInCategory="1" />
 </GROUP>
</MENU>

 /res/menu   menus.xml   android:orderInCategory="1"菜单的位置

@Override
public boolean onCreateOptionsMenu(Menu menu) {
	MenuInflater inflater = getMenuInflater();
	inflater.inflate(R.menu.menus, menu);
	return super.onCreateOptionsMenu(menu);
}

 

@Override
public boolean onOptionsItemSelected(MenuItem item) {
	switch (item.getItemId()) {
	case R.id.New:
		doSmth();
		break;
	case R.id.Save:
		doSmth();
		break;
	}
	return super.onOptionsItemSelected(item);
}

 

Group Category tag

view source 
   
 
   
 
   print 
   ? 
   
 
1
 <GROUP android:id="@+id/some_group_id " android:menuCategory="secondary"> </GROUP> 
 
Checkable Behavior tag
You can use it for group: 
 
   view source 
   
 
   
 
   print 
   ? 
   
 
1
 <GROUP android:id="@+id/noncheckable_group" android:checkableBehavior="none"></GROUP> 
 
And also for menu item:
 
 
   view source 
   
 
   
 
   print 
   ? 
   
 
1
 <ITEM android:id=".." android:title="…" android:checked="true" /> 
 
Submenu tag
 
 
   view source 
   
 
   
 
   print 
   ? 
   
 
1
 <ITEM android:title="Submenu">  
 
  
2
 <MENU>  
 
  
3
 <ITEM… />  
 
  
4
 </MENU>  
 
  
5
</ITEM>
 
Menu Icon tag
 
 
   view source 
   
 
   
 
   print 
   ? 
   
 
1
 <ITEM android:id=".. " android:icon="@drawable/yourImageFile" /> 
 
Menu Enabling/Disabling tag
 
 
   view source 
   
 
   
 
   print 
   ? 
   
 
1
 <ITEM android:id=".. " android:icon="@drawable/yourImageFile" android:enabled="true" /> 
 
Menu Item Shortcut tag
 
 
   view source 
   
 
   
 
   print 
   ? 
   
 
1
 <ITEM android:id="… " android:alphabeticShortcut="n" /> 
 
Menu Visibility tag
 
 
   view source 
   
 
   
 
   print 
   ? 
   
 
1
 <ITEM android:id="… " android:visible="true" />

标签:xml,菜单,source,menu,Menus,tag,Menu,print,view
From: https://blog.51cto.com/u_16166892/6535802

相关文章

  • Android Xml文件生成,Xml数据格式写入
    生成xml文件格式数据,Android提供了Xml.newSerializer();,可以理解为Xml序列化;序列化:把内存里面的数据(file,databases,xml等等)丢给某一个地方; 反序列化:把某个地方的数据(file,databases,xml等等),拿到内存中;既然是Android操作Xml,就用Android所提供的API,不用Java所提供的API,DOM......
  • Android Kotlin 底部菜单栏
    LoginSuccessActivity布局<?xmlversion="1.0"encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tool......
  • 世界知名XML专家力作 ——《重构HTML:改善Web应用的设计》
    世界知名XML——《重构HTML:改善Web媒体评论Elliotte的著作在我的书架上始终占据一席之地。……他通过本书把重构的益处带入了HTML世界。                                   ——MartinFowler ......
  • 安卓开发级联显示菜单-省市区显示举例
    问题背景安卓日常开发过程,经常会有需要级联显示的场景,比如省市区显示等,或者各种组织结构级联显示,本文将介绍安卓开发过程实现级联显示的一种方案。实现效果如下:问题分析思路分析:考虑将要是的省、市、区设计成一种字典迭代结构,数据结构如下:/***组织实体类*/classOrgan......
  • GridView做所有程序主菜单
    <?xmlversion="1.0"encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="fill_parent"android......
  • webView中长按后取消菜单js实现
    <!DOCTYPEhtml><html><head><script>functionabsorbEvent_(event){vare=event||window.event;e.preventDefault&&e.preventDefault();e.stopPropagation&&e.stopPropagation();......
  • JSON及XML学习总结
    1.手写JSON中字符串转java对象的方式//构建java对象Studentstudent=newStudent();//利用JSON类中的toJSON对象转换成JSON字符串Strings=JSON.toJSON(Student).toString();2.手写java对象转JSON字符串的方式Stringss="{\"skills\":[\"1\",\"2\",\"足球\&qu......
  • 菜单的程序控件出现和消失
    @OverridepublicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.main);ButtonmenuButton=(Button)findViewById(R.id.menuButton);menuButton.setOnClickListener(newView.OnClickListener(){......
  • 用代码从xml整形数组中取出每个整数以及tabHost使用light主题的问题
    res/values/integers.xml<?xmlversion="1.0"encoding="utf-8"?><resources><integer-arrayname="UserBases"><item>2</item><item>8</item><it......
  • 扩展LinearLayout以及从xml中加载menu,selector的使用
    在包.com.test1.android.anim中为什么单独写这个包名要用到publicclassSlidingPanelextendsLinearLayout{ privateintspeed=300; privatebooleanisOpen=false; publicSlidingPanel(finalContextctxt,AttributeSetattrs){ super(ctxt,attrs); TypedArr......