android状态栏

  1. 5.0以上的处理:

    自5.0引入 Material Design ,状态栏对开发者更加直接,可以直接调用 setStatusBarColor 来设置状态栏的颜色.在oncreat方法中直接调用

    getWindow().setStatusBarColor(getResources().getColor(R.color.color_1f2326));即可

  2. 一般我们采用下面方法直接设置为透明,无论是5.0以上还是5.0以下都可以适配但是要注意的事在布局文件中加入以下两行
    1. android:fitsSystemWindows="true"  
    2. android:clipToPadding="true" 
  3. public class MainActivity extends Activity {  
  4.   
  5.     @Override  
  6.     protected void onCreate(Bundle savedInstanceState) {  
  7.         super.onCreate(savedInstanceState);  
  8.         setContentView(R.layout.activity_main);  
  9.   
  10.         //透明状态栏  
  11.         getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);  
  12.         //透明导航栏  
  13.         getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);  
  14.   
  15.     }  
  16. }  
  17. 在布局文件中直接如下
  18. <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:fillViewport="true"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:background="@color/color_white"
        >
        <LinearLayout
            android:fitsSystemWindows="true"
            android:clipToPadding="true"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/color_1f2326"
            android:orientation="vertical">
            <LinearLayout
                android:layout_marginBottom="@dimen/px20"
                android:layout_width="match_parent"
                android:layout_height="@dimen/px70"
                android:orientation="horizontal"
                >

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值