xml文件
<?xml version="1.0" encoding="UTF-8" ?><LinearLayout
xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”
xmlns:android=“http://schemas.android.com/apk/res/android”
xsi:noNamespaceSchemaLocation=“layout.xsd”
android:layout_height=“match_parent”
android:layout_width=“match_parent”
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="horizontal"
android:padding="5dp"
android:cornerRadius="10dp"
android:background="#66000000">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="18dp"
android:tag="msg"
android:textColor="#ffffff"
android:text="爱 好: "/>
</LinearLayout>
function
function toast_yimi(msg,time,x,y) {
if(!msg){
logd(‘toast_yimi__空字符串’)
return;
}
let diff = msg.length * 12;
x = x || device.getScreenWidth()/2 - diff;
y = y || (device.getScreenHeight()/5)*4;
time = time || 3000;
thread.execAsync(function () {
let tag = 'toast_ym'
floaty.close(tag)
floaty.touchable(tag,false);
floaty.focusable(tag,false)
let view = floaty.showFloatXml(tag,'toast_ym.xml',x,y);
let textV = view.findViewWithTag('msg');
ui.setViewValue(textV,msg);
sleep(time);
floaty.close(tag);
})
}
main.js 调用
toast_yimi(‘我的信息我的信息我的信息我的信息我的信息’,1000)