0
我需要在ActionBar中有一个自定义菜单项,它只是显示一些自定义的格式化文本。所以我想我会立即创建一个图像并将其附加到菜单图标上。所以在我的代码,我想我可以使用布局XML来编写我的文字:ActionBarSherlock中的自定义菜单项
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView android:textColor="#bcbcbb"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Some Text"/>
<TextView android:textColor="#ffffff"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/replace_text" android:text="XXXX"/>
</LinearLayout>
然后创建一个临时的布局绘制到DrawableBitmap:
后 LinearLayout layout = (LinearLayout)View.inflate(getApplicationContext(), R.layout.refund_text, null);
layout.setDrawingCacheEnabled(true);
layout.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
layout.layout(0, 0, mRefundLayout.getWidth(), layout.getHeight());
layout.buildDrawingCache(true);
Bitmap bitmap = Bitmap.createBitmap(layout.getDrawingCache());
BitmapDrawable bm = new BitmapDrawable(getBaseContext().getResources(), bitmap);
layout.setDrawingCacheEnabled(false);
....do something with the bitmap
但是该措施呼叫宽度和高度仍然是零。谁能告诉我我做错了什么?
问候 李