uniapp在App端如何动态修改原生导航栏?

uniapp在App端如何动态修改原生导航栏?

文章目录

  • 在App端可以通过得到 webview 对象,通过当前 webview 对象的 setTitleNViewButtonBadgesetTitleNViewButtonStylesetTitleNViewSearchInputFocussetTitleNViewSearchInputText 分别对 TitleNView 上的按钮角标,按钮,输入框等组件的样式进行修改。

page.json配置

  • 举个例子,这里配置基本 buttons,根据需要自行配置,具体查看官方文档
json 复制代码
{
    "path": "pages/devices/devices",
    "style": {
        "navigationBarTitleText": "Device",
        "enablePullDownRefresh": true,
        "app-plus": {
            "titleNView": {
                "buttons": [{
                    "text": "Search",
                    "color": "#fff",
                    "fontSize": "18",
                    "width": 80,
                    "float": "right"
                }]
            }
        }
    }
},

修改 buttons 文字

javascript 复制代码
// #ifdef APP-PLUS
var webView = this.$mp.page.$getAppWebview();
changeNavButtonText(text) {
    // 0:按钮索引(index)
    webView.setTitleNViewButtonStyle(0, {
        text: text
    });
}
// #endif

修改按钮上的角标

javascript 复制代码
// index: 按钮索引, text: 角标文本内容
changeNavButtonBadge() {
    webView.setTitleNViewButtonBadge({
        index: 0,
        text: 99,
    });
}

设置 searchInput的 focus

javascript 复制代码
// focus: true | false  
webView.setTitleNViewSearchInputFocus(true)  

设置 searchInput的 text

javascript 复制代码
webView.setTitleNViewSearchInputText(text)

参考文章

相关推荐
suliqiang1 小时前
【前端技术】 Web 前端技术36年 演进全景图
信息可视化·微信小程序·小程序·前端框架·uni-app·人机交互·xcode
梦曦i19 小时前
uni-router v0.2.0重磅发布:全链路拦截+重复导航优化
前端·uni-app
EatFan19 小时前
【实战经验】uni-app使用 SSE 踩坑,EventSource不支持怎么办?
android·后端·ios·uni-app
凡泰AI1 天前
如何为政务 APP 搭建开放平台,实现多部门、第三方供应商标准化入驻与统一管理
android·大数据·小程序·uni-app·app·政务
梦曦i2 天前
@meng-xi/uni-router 未来展望:夯实基础、深化体验、探索前沿
前端·uni-app
2501_916007472 天前
使用Apple Dashboards显示和自定iOS应用性能指标与数据可视化指南
android·ios·小程序·https·uni-app·iphone·webview
爱折腾的编程老炮2 天前
潮玩小程序订单模型-一张表装下所有玩法
spring boot·小程序·uni-app
两个人的幸福online2 天前
UniApp 对接 IM 即时通讯全攻略(下篇)
uni-app
2501_915106322 天前
Flutter iOS混淆打包详细教程与步骤
android·flutter·ios·小程序·uni-app·iphone·webview
DK185838322523 天前
【源码开源部署】电竞代练护航陪玩小程序:全游戏服务平台完整解决方案(附宝塔部署教程)
游戏·微信小程序·uni-app·开源·php