码迷,mamicode.com
首页 > 其他好文 > 详细

ionic2 改变状态栏颜色

时间:2017-08-29 11:06:50      阅读:280      评论:0      收藏:0      [点我收藏+]

标签:blank   config   uil   specific   oncreate   oid   for   set   component   

 

有一个点要特别注意,就是!安卓版本要5.0以上

参考文章:https://segmentfault.com/a/1190000009078477

其中头两项是修改MainActivity.java文件,以下是修改后的MainActivity.java文件的所有内容

MainActivity.java的路径为:platforms\android\src\com\ionicframework\

/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/

package com.ionicframework.smartwms328018;

import android.os.Bundle;
import org.apache.cordova.*;
import android.os.Build;
import android.view.View;

public class MainActivity extends CordovaActivity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// Set by <content src="index.html" /> in config.xml

//安卓状态栏透明
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
}

loadUrl(launchUrl);
}
}

第二步:在项目根目录的config.xml文件中添加下面配置,这里需要注意
颜色的设置至关重要,此处是八位hex color,前两位是透明度,后六位是rgb颜色值.so根据自己的需要配置.
<preference name="StatusBarBackgroundColor" value="#551b1d23" />

 

第三步: 在app.scss中添加样式

 
.platform-android {
    ion-header {
      padding-top: $cordova-md-statusbar-padding;
      background-color: color($colors, primary);
    }
}


第四步: 在appComponent.ts 文件中添加下面这段代码
platform.ready().then(() => {
   if (this.platform.is(‘android‘)) {
       this.statusBar.backgroundColorByHexString("#55fb7981");
   }
})

ionic2 改变状态栏颜色

标签:blank   config   uil   specific   oncreate   oid   for   set   component   

原文地址:http://www.cnblogs.com/maochunyan/p/7446904.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!