我一直在按照本教程来实现Write Java code in nativescript and use directly in typescript
但我有一个错误Cannot read property 'MyToast' of undefined
app.component.ts:
import {Component} from "@angular/core";
let application = require("application");
declare var org:any;
@Component({
selector: "my-app",
templateUrl: "app.component.html",
})
export class AppComponent {
public onTap() {
org.example.MyToast.showToast(application.android.context,"You pressed the button","short");
}
}
我在平台-> src -> java -> org ->example中创建了 MyToast.java类:
package org.example;
import android.widget.Toast;
import android.content.Context;
public class MyToast{
public static void showToast(Context context,String text ,String StrDuration ){
Toast.makeText(context,text, Toast.LENGTH_SHORT).show();
}
}