8***@qq.com
8***@qq.com
  • 发布:2019-03-13 17:53
  • 更新:2019-03-13 17:57
  • 阅读:4156

原生导航栏怎么设置左右两边离屏幕的距离?

分类:uni-app

1: 原生导航栏怎么设置左右两边离屏幕的距离?

"navigationBarTitleText": "导航栏带搜索框",
"app-plus": {
"titleNView": {
"buttons": [ //原生标题栏按钮配置,
{
//原生标题栏增加分享按钮,点击事件可通过页面的 onNavigationBarButtonTap 函数进行监听
"text": "\ue468",
"fontSrc": "/static/uni.ttf",
"fontSize": "40px" ,
"color": "#7b7d80",
"float":"right",
"margin-right":"400px"
}
],
"searchInput": {
"backgroundColor": "#f6f6f6",
"borderRadius": "17px",
"borderWidth": "0px",
"width":"100px",
"fontSize": "13px",
"placeholder": "请输入关键词 如:大白猫",
"disabled": false,
"align":"left",
"margin-left":"400px"
}

                }  
            }  

设置 searchInput左边的距离
buttons右边的距离
searchInput的样式没办法调整?

————————————————————————————————————————

2: 采用JS代码里实现
index.vue 代码?

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": "20px",
"right": "50px",
"top": "7px",
"bottom": "7px"
},
"rectStyles": {
"color": "#f6f6f6",
"radius": "30px",
"borderColor": "#999"
}
},
{
"tag": "font",
"id": "font",
"text": "\ue466",
"position": {
"left": "25px",
"width": "30px",
"top": "7px",
"bottom": "7px"
},
"textStyles": {
"size": "13px",
"fontSrc": "/static/uni.ttf",
"color": "#999"
}
},
{
"tag": "input",
"id": "input",
"position": {
"left": "50px",
"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('获得焦点')
uni.navigateTo({
url: '/pages/index/nav-search'
});
},
onBlur: function(e) {
console.log('失去焦点')
}
}
},
{
"tag": "font",
"id": "fonts",
"text": "\ue468",
"position": {
"right": "15px",
"width": "30px",
"top": "7px",
"bottom": "7px"
},
"textStyles": {
"size": "30px",
"fontSrc": "/static/uni.ttf",
"color": "#999"
}
}]
);
}

可以实现了

问题又来了,做原生导航又出问题

index.nvue 代码

var pages = getCurrentPages();

错误提示: [ERROR] : __ERROR

导航栏空白。

请问怎么解决?谢谢,只要1个解决就可以!

2019-03-13 17:53 负责人:无 分享
已邀请:
DCloud_heavensoft

DCloud_heavensoft

修改button的宽度,可以控制button内容距离屏幕边缘的位置。因为button内容默认是居中的

  • 8***@qq.com (作者)

    "titleNView": {

    "buttons": [ //原生标题栏按钮配置,

    {

    //原生标题栏增加分享按钮,点击事件可通过页面的 onNavigationBarButtonTap 函数进行监听

    "text": "\ue468",

    "fontSrc": "/static/uni.ttf",

    "fontSize": "40px" ,

    "color": "#7b7d80",

    "width":"54px"

    }

    ],

    "searchInput": {

    "backgroundColor": "#f6f6f6",

    "borderRadius": "17px",

    "borderWidth": "0px",

    "width":"300px",

    "fontSize": "13px",

    "placeholder": "请输入关键词 如:大白猫",

    "disabled": false,

    "align":"left"

    }

    }

    谢谢!

    button 离右边的距离可以调整,

    searchInput. 左边的距离怎么设置?width 没作用

    2019-03-13 21:25

  • w***@163.com

    nb

    2022-12-14 16:15

8***@qq.com

8***@qq.com (作者) - IT

无法设置
searchInput左边的距离
buttons右边的距离
searchInput的样式没办法调整?

index.nvue的代码:```javascript
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": "20px",
"right": "50px",
"top": "7px",
"bottom": "7px"
},
"rectStyles": {
"color": "#f6f6f6",
"radius": "30px",
"borderColor": "#999"
}
},
{
"tag": "font",
"id": "font",
"text": "\ue466",
"position": {
"left": "25px",
"width": "30px",
"top": "7px",
"bottom": "7px"
},
"textStyles": {
"size": "13px",
"fontSrc": "/static/uni.ttf",
"color": "#999"
}
},
{
"tag": "input",
"id": "input",
"position": {
"left": "50px",
"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('获得焦点')
uni.navigateTo({
url: '/pages/index/nav-search'
});
},
onBlur: function(e) {
console.log('失去焦点')
}
}
},
{
"tag": "font",
"id": "fonts",
"text": "\ue468",
"position": {
"right": "15px",
"width": "30px",
"top": "7px",
"bottom": "7px"
},
"textStyles": {
"size": "30px",
"fontSrc": "/static/uni.ttf",
"color": "#999"
}
}]
);
}

该问题目前已经被锁定, 无法添加新回复