gpt4 book ai didi

java - getDrawingCache() 返回空指针异常 - Cordova 插件

转载 作者:行者123 更新时间:2023-11-30 02:33:54 26 4
gpt4 key购买 nike

@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;
}
}

在这里,我在 Cordova 插件中创建 TextView 的位图,但 getDrawingCache() 方法返回 null .. 谷歌后我发现你需要添加 setDrawingCacheEnabled(True) 但这也没有帮助..所以请帮助。 ..

最佳答案

在设置文本后添加这一行

toastTitleView.layout(0, 0, 480, 800);

关于java - getDrawingCache() 返回空指针异常 - Cordova 插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26884124/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com