[英]getDrawingCache() return Null Pointer Exception - Cordova Plugin
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
try {
Log.i(LOG_TAG, "[Custom toast] toastTitle: toastTitle \n toastText:" );
Runnable runnable = new Runnable() {
public void run() {
int duration = Toast.LENGTH_SHORT;
Context context = cordova.getActivity().getApplicationContext();
Toast toast = new Toast(context);
toast.setDuration(duration);
LayoutInflater inflater = LayoutInflater.from(context);
Resources resources = context.getResources();
String packageName = context.getPackageName();
View appearance = inflater.inflate(resources.getIdentifier("main","layout",packageName),null);
toast.setView(appearance);
TextView toastTitleView = (TextView) appearance.findViewById(resources.getIdentifier("textView","id",packageName));
toastTitleView.setText("Title");
toastTitleView.buildDrawingCache();
Bitmap bmp = Bitmap.createBitmap(toastTitleView.getDrawingCache());
toast.show();
}
};
this.cordova.getActivity().runOnUiThread(runnable);
callbackContext.success();
return true;
callbackContext.error("Invalid action");
return false;
} catch (Exception e) {
System.err.println("Exception: " + e.getMessage());
callbackContext.error(e.getMessage());
return false;
}
}
在這里我正在科爾多瓦插件中創建TextView的位圖,但在執行Google之后,getDrawingCache()方法返回null ..我發現您需要添加setDrawingCacheEnabled(True)但這也沒有幫助..所以請幫助...
在設置文字后添加此行
toastTitleView.layout(0, 0, 480, 800);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.