Option Menu background color 변경이 어플 내에서 불가능하다고 하는데요
어떻게 할 방법이 없을까요?
고수님들 알려주세요 ~
/*
* IconMenuItemView is the class that creates and controls the options menu
* which is derived from basic View class. So We can use a LayoutInflater
* object to create a view and apply the background.
*/
protected void optionsMenuSetMenuBackground(){
getLayoutInflater().setFactory( new Factory() {
public View onCreateView ( String name, Context context, AttributeSet attrs ) {
if ( name.equalsIgnoreCase( "com.android.internal.view.menu.IconMenuItemView" ) ) {
try { // Ask our inflater to create the view
// XmlPullParser parser = getResources().getXml(R.layout.custom_menu);
// AttributeSet attributes = Xml.asAttributeSet(parser);
LayoutInflater f = getLayoutInflater();
final View view = f.createView( name, null, attrs );
/*
* The background gets refreshed each time a new item is added the options menu.
* So each time Android applies the default background we need to set our own
* background. This is done using a thread giving the background change as runnable
* object
*/
new Handler().post( new Runnable() {
public void run () {
view.setBackgroundColor(Color.argb(242, 0, 20, 60)); <= backgroud color, drawable, resource 등
}
} );
return view;
}
catch ( InflateException e ) {}
catch ( ClassNotFoundException e ) {}
}
return null;
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
optionsMenuSetMenuBackground();
menu.add(0, MENU_INTERNAL, Menu.NONE, R.string.menu_photo_internal);
menu.add(0, MENU_SDCARD, Menu.NONE, R.string.menu_photo_sdcard);
return true;
}
어플리케이션을 개발 중이시라면 불가능합니다. 다만 안드로이드가 제공해주는 옵션메뉴를 사용하지 않고,
완전히 똑같이 보이게 바닥부터 만드신다면, 그 때는 가능하겠죠.