导航首页 » 文章首页 » 安卓专区 » FusionApp小技巧-收集整合-含远程更新

FusionApp小技巧-收集整合-含远程更新

2024-01-16 163 安卓专区

常用代码

//网页即将加载
if(网页链接:find"url/.")then
  停止加载()
  进入子页面("游览",{链接=网页链接})
end

//加载本地网页
("file:///android_asset/drawable/index.html")

//如何调用浏览器打开当前页面?
import "android.content.Intent"
import "android.net.Uri"
url="https://www.xiaoaiav.com"
viewIntent = Intent("android.intent.action.VIEW",Uri.parse(url))
activity.startActivity(viewIntent)
--浏览器打开链接

//收到新标题
设置顶栏标题(webView.title)

//项目点击事件
进入子页面("子页面名",{链接="url",标题="标题名"})

//去头部留白
document.body.style.paddingTop=0

//显示或隐藏悬浮按钮
--显示悬浮按钮
fltBtn.setVisibility(View.VISIBLE)
--隐藏悬浮按钮
fltBtn.setVisibility(View.GONE)
注:fltBtn为悬浮按钮的ID,不需要更改。

//悬浮点击事件
加载Js([[document.getElementsByClassName("apk_topbar_btn")[0].parentElement.onclick()]])

//悬浮选择点击事件
pop=PopupMenu(activity,fltBtn)
menu=pop.Menu
menu.add("选项一").onMenuItemClick=function(a)
进入子页面("子页面名",{链接="url1"..webView.getUrl()})
end
menu.add("选项二").onMenuItemClick=function(a)
进入子页面("子页面名",{链接="url2"..webView.getUrl()})
end
pop.show()

//设置屏幕方向
import "android.content.pm.ActivityInfo"
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
//视频解析播放
加载网页("vip解析url"..webView.getUrl());
--横屏
activity.setRequestedOrientation(0); 
--竖屏
activity.setRequestedOrientation(1); 

//各控件ID
searchEdtTxt       搜索栏
toolbar.parent        顶栏
toolbar             标题栏
titleTvw            顶栏标题
webView           浏览器
fltBtn              悬浮按钮
 pager             滑动窗体
popmenu_position     菜单栏
sidebar             侧滑栏显示图标
pgsBar             进度条
sideLvw           侧滑图标
menu_button       菜单图标
menuBtn          侧滑栏图标

//开启和关闭侧滑
--打开侧滑
drawerLayout.openDrawer(3)
--关闭侧滑
drawerLayout.closeDrawer(3) 

--均放在点击事件
--自定义底栏点击事件

index=1--底栏项目序号

bmBarLin.getChildAt(index-1).onClick=function()
--点击事件
end

--自定义标签栏点击事件

local index=1--标签栏项目序号

tabBar.getChildAt(index-1).onClick=function()

 --点击事件

end
-- 多页面搜索 --
-- By: QQ3
local urls={"https://www.google.com/search?q=%s","https://m.baidu.com/s?wd=%s","https://m.so.com/s?q=%s","http://cn.bing.com/search?q=%s","http://m.chinaso.com/page/search.htm?keys=%s","https://m.sogou.com/web/searchList.jsp?keyword=%s","https://m.sm.cn/s?q=%s"}
searchEdtTxt.setOnEditorActionListener{
  onEditorAction=function(view,action,event)
    local text=tostring(view.text)
    if text~=nil and text~="" then
      searchEdtTxt.setHint(text)
      local URLEncodeer=import"java.net.URLEncoder"
      for index in pairs(urls) do
        if allWebView[index] and urls[index]~=nil and urls[index]~="" then
          local url=tostring(urls[index]):format(URLEncoder.encode(text))
          if pager.getCurrentItem()+1==index then
            task(100,function()allWebView[index].loadUrl(url)end)--解决当前页面无法加载(与默认搜索事件冲突被覆盖)的问题
          else
            allWebView[index].loadUrl(url)
          end
        end
      end
    else
      SearchEdtTxt.setHint("")
    end
  end
}


网页顶栏及头部空白物理遮盖

javascript:
if(document.getElementsByTagName('BODY')[0].scrollTop<46){
      document.getElementsByTagName('BODY')[0].scrollTop=46;
    } else {
      return false;
    }


浮动广告查杀脚本

var d=document;var s=d.createElement('script');s.setAttribute('src', 'https://greasyfork.org/scripts/7410-jskillad/code/jsKillAD.user.js');d.head.appendChild(s);


清除缓存

//第一部分、程序启动
//自定义事件
function clr()  
  import "java.io.File" 
  items={"浏览记录","缓存文件"}
  多选对话框=AlertDialog.Builder(this)
  .setTitle("清除记录")  
  .setPositiveButton("确定",function()
    if clearhistory==1 and clearall==1 then
      File(lstads).delete()
      File(lstwebads).delete()
      lst={}
      lstweb={}
      os.execute("pm clear "..activity.getPackageName())
    elseif clearhistory==0 and clearall==1 then
      os.execute("pm clear "..activity.getPackageName())
    elseif clearhistory==1 and clearall==0 then
      File(lstads).delete()
      File(lstwebads).delete()
      lst={}
      lstweb={}
    else return nil
    end
  end)
  .setMultiChoiceItems(items, nil,{ onClick=function(v,p)     
      if p==0 then clearhistory=1
      end    
      if p==1 then clearall=1
      end
    end})
  多选对话框.show();
  clearhistory=0
  clearall=0
end

//分割线
//第二部分 填入点击事件
clr()


网络检测

--程序启动时会执行的事件
--程序启动事件
--网络检测
manager = activity.getSystemService(Context.CONNECTIVITY_SERVICE); 
gprs = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState(); 
if tostring(gprs)== "CONNECTED" then
--连接
print("你娃儿流量真多")
--上面括号内容可任意修改或者删除print打印事件
else
connManager = activity.getSystemService(Context.CONNECTIVITY_SERVICE)
mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if tostring(mWifi):find("none") then
--未连接
print("网络未连接")
--上面括号内容可任意修改(不建议删除)
else
--连接
print("正在使用WIFI网络")
--上面括号内容可任意修改或者删除print打印事件
end
end
--将所有的代码放入程序启动事件里面.


fusionapp布局

--浏览器布局

browser=
--布局这里写
webView.addView(loadlayout(browser))


线性布局

线性布局按照垂直或者水平的顺序依次排列子元素,每一个子元素都位于前一个元素之后。

垂直排列,那么将是一个N行单列的结构,每一行只会有一个元素,而不论这个元素的宽度为多少;

水平排列,那么将是一个单行N列的结构。

搭建两行两列的结构,通常的方式是先垂直排列两个元素,每一个元素里再包含一个LinearLayout进行水平排列也就是说纵向和横向还是可以相互嵌套使用的哦,可以实现表格布局的效果。

{
LinearLayout;
orientation='';--重力属性
layout_width='';--布局宽度
layout_height='';--布局高度
background='';--布局背景颜色(或者图片路径)
};


相对布局

最为常用的布局之一,也是最强大的布局:

*它可以设置的属性非常的多。

安卓屏幕的分辨率大小不一,所以想到屏幕的自适应性,开发中建议大家去使用相对布局。

相对于元素来说,比较容易定位

{
RelativeLayout;
orientation='';--重力属性
layout_width='';--布局宽度
layout_height='';--布局高度
background='';--布局背景颜色(或者图片路径)
};


绝对布局

通常不采用此布局格式。

它的界面代码过于刚性。

有可能不能很好的适配各种终端

{
AbsoluteLayout;
orientation='';--重力属性
layout_width='';--布局宽度
layout_height='';--布局高度
background='';--布局背景颜色(或者图片路径)
};


帧布局(框架布局)

是最简单的布局形式,所以在实际开发中用得比较少。所有添加到这个布局中的视图都以层叠的方式显示。第一个添加的控件被放在最底层,最后一个添加到框架布局中的视图显示在最顶层,上一层的控件会覆盖下一层的控件。这种显示方式有些类似于堆栈。

{
FrameLayout;
orientation='';--重力属性
layout_width='';--布局宽度
layout_height='';--布局高度
background='';--布局背景颜色(或者图片路径)
};


简单实现远程更新

URL="https://www.iermeiapp.com/app/app.txt"--你的远端数据的地址
Http.get(URL,function(code,cont)
    if code ~= 200 then --如果服务器返回数据异常,`
        print("服务器失联")
        activity.finish()
    end
    --cont就是服务器返回的数据,之后所有的代码都写在这里
    --local用来声明局部变量,及这里的所以东西对你的其他代码的都没有任何影响。
    local PackageName=this.getPackageName()--包名
    local PackInfo=this.getPackageManager().getPackageInfo(PackageName,64)--包信息
    local 本地版本=tonumber(PackInfo.versionCode)--版本号,这是我们要用的
    --由于之后需要进行判断,因此此处使用tonumber()方法转换为数字
    local 远端版本=cont:match("【版本】(.-)【版本】")
    local 下载地址=cont:match("【链接】(.-)【链接】")
    if tonumber(远端版本)>本地版本 then
        --提示检测更新
        import "android.content.Intent"
        import "android.net.Uri"
        local viewIntent = Intent("android.intent.action.VIEW",Uri.parse(下载地址))
        activity.startActivity(viewIntent)
    --顺带提醒下用户,免得他们一脸懵逼
    print("请在打开的页面中下载更新并安装~")
    --当然如果你想强制更新的话,可以把下面这一行加上
       -- activity.finish() 
--结束程序
    end
end)


网页添加夜间模式

加载Js([[javascript:(function(){var styleElem=null,doc=document,ie=doc.all,fontColor=50,sel="body,body *";styleElem=createCSS(sel,setStyle(fontColor),styleElem);function setStyle(fontColor){var colorArr=[fontColor,fontColor,fontColor];return"background-color:#212121 !important;color:RGB("+colorArr.join("%,")+"%) !important;"}function createCSS(sel,decl,styleElem){var doc=document,h=doc.getElementsByTagName("head")[0],styleElem=styleElem;if(!styleElem){s=doc.createElement("style");s.setAttribute("type","text/css");styleElem=ie?doc.styleSheets[doc.styleSheets.length-1]:h.appendChild(s)}if(ie){styleElem.addRule(sel,decl)}else{styleElem.innerHTML="";styleElem.appendChild(doc.createTextNode(sel+" {"+decl+"}"))}return styleElem}})();]])


上一篇
161

Fusion APP制作的APP更新教程