onCreateOptionsMenu中 图标,文字创建
查看次数376306 发表时间2012-09-25 21:54:17
1 方法一,文字图标在xml规划好,文字定义在string.xml,图片直接从工程文件中调用,至于所有的文字图片排版,放在单独的menu.xml文件中
(转发请注明转自:学PHP)
1 |
@Override |
2 |
public
boolean onCreateOptionsMenu(Menu menu) {
|
3 |
super .onCreateOptionsMenu(menu);
|
4 |
MenuInflater menuInflater = getMenuInflater();
|
5 |
menuInflater.inflate(R.menu.menu, menu);
|
6 |
return
true ; |
7 |
} |
01 |
<? xml
version = "1.0"
encoding = "UTF-8"
?> |
02 |
< menu
xmlns:android = "http://schemas.android.com/apk/res/android" >
|
03 |
< item
android:icon = "@android:drawable/ic_menu_mylocation" |
04 |
android:id = "@+id/centerOnLocationMenuItem"
android:title = "@string/myLocation"
/> |
05 |
< item
android:icon = "@android:drawable/ic_menu_more"
android:id = "@+id/chooseStop" |
06 |
android:title = "@string/chooseStop"
/> |
07 |
< item
android:icon = "@android:drawable/ic_menu_mylocation" |
08 |
android:id = "@+id/centerOnBostonMenuItem"
android:title = "@string/bostonsLocation"
/> |
09 |
< item
android:icon = "@android:drawable/ic_menu_preferences" |
10 |
android:id = "@+id/settingsMenuItem"
android:title = "@string/settings"
/> |
11 |
< item
android:icon = "@android:drawable/ic_menu_more"
android:id = "@+id/chooseRoute" |
12 |
android:title = "@string/chooseRoute"
/> |
13 |
< item
android:icon = "@android:drawable/ic_menu_rotate"
android:id = "@+id/refreshItem" |
14 |
android:title = "@string/refresh"
/> |
15 |
</ menu > |
2,动态创建菜单
01 |
@Override |
02 |
public
boolean onCreateOptionsMenu(Menu menu) { |
03 |
// TODO Auto-generated method stub
|
04 |
menu.add( 0 , LOCATION,
1 , R.string.location);
|
05 |
menu.add( 0 ,SEARCH, 2 ,R.string.search);
|
06 |
menu.add( 0 , SHOWROUTE,
3 , R.string.vechicleLocation);
|
07 |
menu.add( 0 , ALLROUTE,
4 , R.string.allRoute);
|
08 |
return
super .onCreateOptionsMenu(menu);
|
09 |
} |
10 |
|
11 |
public
boolean onCreateOptionsMenu(Menu menu) |
12 |
{ |
13 |
menu.add( 0 , CLASSIC_MENU_REFRESH,
0 , R.string.menu_refresh).setIcon(R.drawable.cmcc_toolbar_refresh);
|
14 |
return
super .onCreateOptionsMenu(menu);
|
15 |
} |
(转发请注明转自:学PHP)
相关推荐
- Android中的Button自定义点击效果 (2012-09-26 22:38:05)
- Android 以特定格式显示当前时间 (2012-09-26 22:38:08)
- Android位置策略(一) (2012-09-29 07:19:04)
- Android Context 详解 (2012-09-29 07:20:30)
- Android 广播大全 Intent Action 事件 (2012-09-29 07:20:38)
- android 学习笔记十一 可视化频率(频谱) (2012-09-10 23:13:19)
- Android之进程与线程 (2012-09-10 23:13:07)
- [android]控件ImageView的常用属性 (2012-09-04 15:12:07)
- android 获取应用证书及签名信息 (2012-09-04 15:12:01)
- [android]控件Button常用属性 (2012-09-04 15:08:26)
发表评论