package com.huawei.st;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.util.AttributeSet;
import android.view.InflateException;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;

public class Test1 extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.home_timeline_menu, menu);

setMenuBackground();
return true;
}

protected void setMenuBackground() {
Test1.this.getLayoutInflater().setFactory(
new android.view.LayoutInflater.Factory() {
/**
* name - Tag name to be inflated.<br/>
* context - The context the view is being created in.<br/>
* attrs - Inflation attributes as specified in XML file.<br/>
*/
public View onCreateView(String name, Context context,
AttributeSet attrs) {
// 指定自定义inflate的对象
if (name.equalsIgnoreCase("com.android.internal.view.menu.IconMenuItemView")) {
try {
LayoutInflater f = getLayoutInflater();
final View view = f.createView(name, null,
attrs);
new Handler().post(new Runnable() {
public void run() {
// 设置背景图片
view.setBackgroundResource(R.drawable.bg_state);
}
});
return view;
} catch (InflateException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
return null;
}
});
}

}

更多相关文章

  1. 类和 Json对象
  2. Android学习笔记(14)————Socket在Android上面的应用
  3. Android文件下载程序例子
  4. Android(安卓)文件压缩和解压
  5. NDK旧版本下载地址
  6. android 唤醒屏幕并解锁
  7. Android之SurfaceView学习一
  8. android camera 通过onPreviewFrame采集视频
  9. Android实现DES对字符串加密

随机推荐

  1. Android中如何把bitmap存成BMP格式的图片
  2. Android培训班(32)
  3. Android-->原生API搭建Android Http服务
  4. Android中SparseArray源码实现
  5. 刘海屏适配
  6. Android彩信发送
  7. android 修改图片的颜色
  8. 设置toolbar中弹出的menu菜单在toolbar的
  9. android adb shell获取和设置IP相关信息
  10. Android Listview设置监听器并获取子项数