我将主页菜单添加到我的应用程序中,我需要将菜单文本作为中心对齐。在姜面包中工作正常。但它在冰淇淋三明治中保持对齐。我可以解决这个问题吗?
这是我的菜单布局
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/menu_home"
android:title="@string/home"
/>
</menu>
截图:
img http://img594.imageshack.us/img594/5756/device20121123152830.png
答案 0 :(得分:0)
getLayoutInflater().setFactory( new Factory() {
@Override
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
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.setBackgroundResource( R.drawable.bg_btn1);
view.setPadding(left, top, right, bottom);
}
} );
return view;
}
catch ( InflateException e ) {}
catch ( ClassNotFoundException e ) {}
}
return null;
}
});