index.uts 873 字节
Newer Older
lizhongyi_'s avatar
lizhongyi_ 已提交
1 2 3

import XToast from "com.hjq.xtoast.XToast";
import R from "io.dcloud.uni_modules.uts_toast.R";
4

lizhongyi_'s avatar
lizhongyi_ 已提交
5

杜庆泉's avatar
杜庆泉 已提交
6
class UIRunnable implements Runnable {
lizhongyi_'s avatar
lizhongyi_ 已提交
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37

    override run():void {
		
	
       new XToast<XToast<unknown>>(UTSAndroid.getUniActivity())
       				.setDuration(1000)
       				.setContentView(R.layout.window_hint)
       				.setImageDrawable(android.R.id.icon,  android.R.mipmap.sym_def_app_icon)
       				.setText(android.R.id.message, "一秒后自动消失")
       				.show()

    }
};

export function showToast():boolean{
	let hasXToastIntegration =  true
	try{
		let xToastClass = Class.forName("com.hjq.xtoast.XToast")
		console.log(xToastClass)
	}catch(e:Exception){
		hasXToastIntegration = false;
	}
	
	if(!hasXToastIntegration){
		return false;
	}

	let toastRunable = new UIRunnable();
	UTSAndroid.getUniActivity()!.runOnUiThread(toastRunable)
	return true
}