android menu布局,android 4.2 menu的布局如何控制

禹兴安
2023-12-01

packagecom.cxt.devicetest;importandroid.os.Bundle;importandroid.app.TabActivity;importandroid.content.Intent;importandroid.view.LayoutInflater;importandroid.view.Menu;importandroid.view.Window;importandroid.view.WindowManager;importandroid.widget.TabHost;public class MainActivity extendsTabActivity {privateTabHost tabHost;private Intent system_Information_intent; //系统信息

private Intent hardware_Information_intent; //硬件信息

private Intent software_Information_intent; //软件信息

private Intent runtime_Information_intent; //运行时信息

@Overrideprotected voidonCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);// //隐去标题栏(应用程序的名字)//this.requestWindowFeature(Window.FEATURE_NO_TITLE);// //隐去状态栏部分(电池等图标和一切修饰部分)//this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,//WindowManager.LayoutParams.FLAG_FULLSCREEN);

setContentView(R.layout.activity_main);

tabHost=getTabHost();

initIntent();

addSpec();

}/***

* 初始化各个tab标签对应的intent*/

private voidinitIntent() {

system_Information_intent= new Intent(this, SystemActivity.class);

hardware_Information_intent= new Intent(this, HardWareActivity.class);

software_Information_intent= new Intent(this, SoftwareActivity.class);

runtime_Information_intent= new Intent(this, RuntimeActivity.class);

}/***

* 为tabHost添加各个标签项*/

private voidaddSpec() {

tabHost.addTab(this.buildTagSpec("tab_system", R.string.system,

R.drawable.menu_about_icon, system_Information_intent));

tabHost.addTab(this.buildTagSpec("tab_hardware", R.string.hardware,

R.drawable.menu_map_icon, hardware_Information_intent));

tabHost.addTab(this.buildTagSpec("tab_software", R.string.software,

R.drawable.menu_forum_icon, software_Information_intent));

tabHost.addTab(this.buildTagSpec("tab_runtime", R.string.runtime,

R.drawable.menu_service_icon, runtime_Information_intent));

}/***

* 自定义创建标签项的方法

*

*@paramtagName

* 标签标识

*

*@paramtagLable

* 标签文字

*

*@paramicon

* 标签图标

*

*@paramcontent

* 标签对应的内容

*

*@return

*/

private TabHost.TabSpec buildTagSpec(String tagName, inttagLable,inticon, Intent content) {returntabHost

.newTabSpec(tagName)

.setIndicator(getResources().getString(tagLable),

getResources().getDrawable(icon)).setContent(content);

}

@Overridepublic booleanonCreateOptionsMenu(Menu menu) {//Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.menu.main, menu);return true;

}

}

 类似资料: