提交 3a1e871b 编写于 作者: 杜庆泉's avatar 杜庆泉

utssdk dir add

上级 dbdba79e
......@@ -7,6 +7,11 @@
<button type="primary" @tap="testClearInterval">关闭定时任务</button>
</view>
<view class="uni-btn-v uni-common-mt">
<button type="primary" @tap="testAddToDecorView">添加TextView至视图顶层</button>
<button type="primary" @tap="testRemoveToDecorView">移除视图顶层的TextView</button>
</view>
</view>
</template>
<script>
......@@ -14,7 +19,8 @@
doTimerTask,
doIntervalTask,
clearIntervalTask,
getDecorViewInfo
addViewToDecorView,
removeViewToDecorView
} from "../../../uni_modules/uts-advance";
export default {
......@@ -66,6 +72,13 @@
clearIntervalTask(this.taskId);
},
testAddToDecorView: function () {
addViewToDecorView();
},
testRemoveToDecorView: function () {
removeViewToDecorView();
},
}
......
......@@ -76,16 +76,7 @@
"联盟": "u"
}
}
},
"type": "uts",
"uts": {
"android": {
"libs": [],
"dependencies": []
},
"ios": {
"libs": []
}
}
}
}
}
\ No newline at end of file
import { getActivity } from "io.dcloud.uts.android";
import { getUniActivity } from "io.dcloud.uts.android";
import Rect from "android.graphics.Rect";
import Color from "android.graphics.Color";
import TextView from "android.widget.TextView";
import FrameLayout from "android.widget.FrameLayout";
import ViewGroup from "android.view.ViewGroup";
import Gravity from "android.view.Gravity";
type TimerOptions = {
start: (res: string) => void;
......@@ -41,4 +43,58 @@ export function clearIntervalTask(taskId:number) {
class AddUIRunnable extends Runnable {
override run():void {
var textView = TextView(getUniActivity())
textView.text = "HELLO WORLD"
textView.textSize = 30.0.toFloat();
textView.setBackgroundColor(Color.RED)
textView.tag = "helloText"
textView.gravity = Gravity.CENTER
var decorView = getUniActivity()!.window.decorView;
var frameContent = decorView.findViewById(android.R.id.content) as FrameLayout
var layoutParam = FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParam.topMargin = 200;
frameContent.addView(textView,layoutParam)
}
};
class RemoveUIRunnable extends Runnable {
override run():void {
var decorView = getUniActivity()!.window.decorView;
var frameContent = decorView.findViewById(android.R.id.content) as FrameLayout
var targetTV = frameContent.findViewWithTag("helloText") as TextView
if(targetTV != null){
frameContent.removeView(targetTV)
}
}
};
export function addViewToDecorView() {
var uiRunable = AddUIRunnable();
// 获取android环境下 宿主decorview的基本信息
getUniActivity()!.runOnUiThread(uiRunable)
}
export function removeViewToDecorView() {
var uiRunable = RemoveUIRunnable();
// 获取android环境下 宿主decorview的基本信息
getUniActivity()!.runOnUiThread(uiRunable)
}
......@@ -76,16 +76,7 @@
"联盟": "u"
}
}
},
"type": "uts",
"uts": {
"android": {
"libs": [],
"dependencies": []
},
"ios": {
"libs": []
}
}
}
}
......@@ -76,17 +76,7 @@
"联盟": "u"
}
}
},
"type": "uts",
"uts": {
"android": {
"libs": [],
"dependencies": []
},
"ios": {
"libs": []
}
}
}
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册