我在操作栏中有一个菜单项。总是看起来很小,如下图所示。
我希望它的大小是大约。这的两倍。我在mdpi,hdpi,xhdpi文件夹中放置了不同大小的图标。因此,这不是与dpi有关的问题。
我在HTC One和xhdpi模拟器中遇到此问题。我尝试将xhdpi文件夹中的图标放大,并在模拟器中进行了测试,但操作栏中的大小没有变化。对于micromax canvas2(hdpi),它可以正常工作。
有什么方法可以设置菜单项的大小以固定高度和宽度?或任何其他解决方法?
我通过对菜单项使用自定义视图解决了此问题。
菜单项的布局:
<ImageButton
android:id="@+id/first_menu_item"
android:layout_width="56dp"
android:layout_height="33dp"
android:layout_gravity="center"
android:contentDescription=""
android:background="@drawable/menu_item_background"
android:gravity="center" />
</LinearLayout>
为活动中的操作栏设置自定义视图:
// Set custom menu items for action bar
LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT, Gravity.RIGHT
| Gravity.CENTER_VERTICAL); // Set Layout Parameters
lp.setMargins(5, 5, 10, 5); // Left, top, right, bottom margins
View view = LayoutInflater.from(this).inflate(
R.layout.actionbar_menu_item, null);
ImageButton menuItem = (ImageButton) view
.findViewById(R.id.first_menu_item);
menuItem.setImageDrawable(getResources().getDrawable(
R.drawable.edit_button));
menuItem.setOnClickListener(this);
actionBar.setCustomView(view, lp);
actionBar.setDisplayShowCustomEnabled(true);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句