小程序页面样式调试

修改导航条背景颜色和字体颜色

uni.setNavigationBarColor({
                    frontColor: "#ffffff",
                    backgroundColor:"#007AFF"
                })

设置小程序显示亮屏

uni.setKeepScreenOn({
            keepScreenOn: true
        });

在微信小程序中,自定义导航栏的颜色 可以在app.json.  window里面添加navigationBarBackgroundColor属性。

但是颜色只能为十六进制颜色码,不能使用rgb,或者rgba.。

为了满足更多用户的需求,微信官方给出了一个navigationStyle属性。

官方文档:navigationStyle 导航栏样式,仅支持 default/custom。custom  模式可自定义导航栏,只保留右上角胶囊状的按钮)。

在app.json window 增加 navigationStyle:custom ,顶部导航栏就会消失,保留右上角胶囊状的按钮,如下图所示。

 

Q:如果改变胶囊体颜色?

A:胶囊体目前只支持黑色和白色两种颜色 在app.josn window 加上 "navigationBarTextStyle":"white/black"

 

注:如果自定义导航栏,页面自带的返回按钮也会消失,需要用代码编写!!!!

Q:如何兼容适配所有机型,包括刘海屏?

A:使用 wx.getSystemInfoSync()['statusBarHeight'] 则能获取到顶部状态栏的高度,单位为px.

简单示例:

在app.js里面
App({
    globalData: {
      statusBarHeight:wx.getSystemInfoSync()['statusBarHeight']
    }
})
WXML 自定义顶部状态栏div结构
<view class="custom flex_center" style="padding-top:{{statusBarHeight}}px">
  <text>demo</text>
</view>
<view class="empty_custom" style="padding-top:{{statusBarHeight}}px"></view>
app.css 全局css中设置样式
.custom{
  position: fixed;
  width: 100%;
  top: 0;
  left: 0;
  height: 45px;
  background: #2C5CFF;
  z-index: 999;
}
.custom text{
  color: #fff;
  font-size: 34rpx;
  font-weight: 500;
  max-width: 280rpx;
}
.empty_custom{
  height: 45px;
  width: 100%;
}
在index.js中取出statusBarHeight值
Page({
    data:{
        statusBarHeight: app.globalData.statusBarHeight
    }
})
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值