y***@qq.com
y***@qq.com
  • 发布:2018-11-07 20:27
  • 更新:2023-09-22 14:17
  • 阅读:24941

【分享】uni-app 原生导航 titleNView 搜索框

分类:uni-app

贴子为以前的,官方已经集成了搜索框了
移步到这里看
https://uniapp.dcloud.io/collocation/pages?id=app-plus

经测试官方已修复安卓的BUG

以下是苹果的


以下是安卓的

操作方法,先配置是下page.json

        {  
            "path": "你的页面",  
            "style": {  
                "backgroundColorTop": "#ebebeb",  
                "backgroundColorBottom": "#ebebeb",  
                "app-plus": {  
                    "scrollIndicator": "none",  
                    "titleNView": {  
                        "titleText":"",//不要设置标题  
                        "buttons": [{  
                            "text": "取消",  
                            "fontSize": "14"  
                        }]  
                    }  
                }  
            }  
        }

不要设置标题,不然在安卓上就会显示出来,画的盖不住

以下操作在您要画搜索框的页面

在onload引用startcreatview就可以了

设置延迟,不做延迟会出现错误

            startcreatview(){  
                var s = this;  
                s.TitleTimer = setTimeout(function() {  
                    s.createView();  
                }, 100);//具体缓迟时间可以按需设置  
            },

            createView() {  
                clearTimeout(this.TitleTimer);  
                var s = this;  
                var pages = getCurrentPages();  
                var page = pages[pages.length - 1];  
                var currentWebview = page.$getAppWebview();  
                var nTitle = currentWebview.getTitleNView();  
                    nTitle.draw(  
                        [{  
                                "tag": "rect",  
                                "id": "rect",  
                                "color": "#999",  
                                "position": {  
                                    "left": "50px",  
                                    "right": "50px",  
                                    "top": "7px",  
                                    "bottom": "7px"  
                                },  
                                "rectStyles": {  
                                    "color": "#f6f6f6",  
                                    "radius": "30px",  
                                    "borderColor": "#999"  
                                }  
                            },  
                            {  
                                "tag": "font",  
                                "id": "font",  
                                "text": "\ue466",  
                                "position": {  
                                    "left": "55px",  
                                    "width": "30px",  
                                    "top": "7px",  
                                    "bottom": "7px"  
                                },  
                                "textStyles": {  
                                    "size": "13px",  
                                    "fontSrc": "/static/uni.ttf",  
                                    "color": "#999"  
                                }  
                            },  
                            {  
                                "tag": "input",  
                                "id": "input",  
                                "position": {  
                                    "left": "80px",  
                                    "right": "70px",  
                                    "top": "7px",  
                                    "bottom": "7px"  
                                },  
                                "inputStyles": {  
                                    "placeholder": "关键字搜索",  
                                    "borderRadius": "30px",  
                                    "borderWidth": "0px",  
                                    "fontSize": "13px",  
                                    "type": "search",  
                                    "fontSrc": "/static/uni.ttf",  
                                    "color": "#999",  
                                    onComplete: function(e) {  
                                        console.log('点击搜索执行' + e.text)  
                                    },  
                                    onFocus: function(e) {  
                                        console.log('获得焦点')  
                                    },  
                                    onBlur: function(e) {  
                                        console.log('失去焦点')  
                                    }  
                                }  
                            }  
                        ]  
                    );  
            },  

如果只需要一个假搜索框,把上面代码的inputStyles部份替换为
"textStyles": {
"size": "13px",
"fontSrc": "/static/uni.ttf",
"color": "#999"
}
同时添加监听假搜索框的点击事件nTitle.addEventListener('click', '点击事件', false);

19 关注 分享
Trust SimpleJalon DCloud_heavensoft AJXMJC mfan 诗小柒 付楚 Songlazy丨zzz Mr王 潇洒 我是卧底 8***@qq.com 无所谓001 哈啤有点苦 Neil_HL sonicsunsky 香蕉不是笨啦啦 9***@qq.com 2***@qq.com

要回复文章请先登录注册

2***@qq.com

2***@qq.com

火钳刘明,非常有用!
2023-09-22 14:17
速翔网络

速翔网络

回复 无所谓001 :
解决了么? 我显示Uncaught TypeError: page.$getAppWebview is not a function
2019-11-20 22:06
yesterdream

yesterdream

能不能监听搜索框change啊,像官方搜索框onNavigationBarSearchInputChanged 一样
2019-06-11 00:16
2***@qq.com

2***@qq.com

你好这个 tag 属性为font时候,点击事件怎么触发
2019-06-10 15:34
Tail前端

Tail前端

回复 y***@qq.com :
没有demo吗
2019-06-04 17:25
8***@qq.com

8***@qq.com

能直接清除搜索框里面的内容吗
2019-03-31 13:23
y***@qq.com

y***@qq.com (作者)

实在对不住大家,近来在写一套多用户系统,没上来看,官方bug修复没有也没注意,使用出错的朋友试下把延迟调高一点试试,多用户系统已经完成,过几天又要回来做app了,到时具体测试一下再回复大家
2018-12-21 01:37
y***@163.com

y***@163.com

给个demo测试一下呗
2018-12-20 22:12
8***@qq.com

8***@qq.com

回复 无所谓001 :
app?我没报错
2018-12-05 21:51
无所谓001

无所谓001

回复 8***@qq.com :
请问,我一直报错 $getAppWebview is not a function是怎么回事
2018-12-04 17:04