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
但是該措施呼叫寬度和高度仍然是零。誰能告訴我我做錯了什麼?
問候 李