Androidメニューに設定オプションを追加しました。エミュレータでのテスト中は正常に動作します。しかし、デバイスで試しても変化しません..何が問題なのか分かりますか? androidmanifest.xml ファイルで何かを変更する必要がありますか。
以下は私のコードです:
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
menu.add(1,1,0,"Settings").setIcon(R.drawable.ic_tab_settings_grey);
setMenuBackground();
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch(item.getItemId())
{
case 1:
Intent in = new Intent(TransactionSummaryActivity.this, WelcomePage.class);
startActivity(in);
finish();
return true;
default:
return true;
}
}
protected void setMenuBackground(){
getLayoutInflater().setFactory( new Factory() {
@Override
public View onCreateView(String name, Context context, AttributeSet attrs) {
// TODO Auto-generated method stub
if ( name.equalsIgnoreCase( "com.android.internal.view.menu.IconMenuItemView" ) ) {
try { // Ask our inflater to create the view
LayoutInflater f = getLayoutInflater();
final View view = f.createView( name, null, attrs );
new Handler().post( new Runnable() {
public void run () {
view.setBackgroundResource(R.drawable.menu_selector);
// view.setBackgroundColor(Color.parseColor("#257CB5"));
((TextView) view).setTextColor(Color.WHITE);
}
} );
return view;
}
catch (InflateException e) {}
catch (ClassNotFoundException e) {}
}
return null;
}
});
}