2019独角兽企业重金招聘Python工程师标准>>>

1、在style.xml中定义toolbar的颜色

 

[html] view plain copy

 print?

  1.   
  2.   
  3.       
  4.       
  5.           
  6.           
  7.         #4876FF  
  8.         true  
  9.       
  10.   
  11.       
  12.   
  13.   


2、布局文件添加属性

 

 

[plain] view plain copy

 print?

  1. android:fitsSystemWindows="true"  
  2. android:clipToPadding="true"  


3、在Activity的onCreate(Bundle savedInstanceState)方法中添加代码

 

 

[java] view plain copy

 print?

  1. @Override  
  2. protected void onCreate(Bundle savedInstanceState) {  
  3.     super.onCreate(savedInstanceState);  
  4.   
  5.     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {  
  6.         Window window = getWindow();  
  7.         window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS  
  8.                 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);  
  9.         window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN  
  10.                 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION  
  11.                 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);  
  12.         window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);  
  13.         //获取样式中的属性值  
  14.         TypedValue typedValue = new TypedValue();  
  15.         this.getTheme().resolveAttribute(android.R.attr.colorPrimary, typedValue, true);  
  16.         int[] attribute = new int[] { android.R.attr.colorPrimary };  
  17.         TypedArray array = this.obtainStyledAttributes(typedValue.resourceId, attribute);  
  18.         int color = array.getColor(0, Color.TRANSPARENT);  
  19.         array.recycle();  
  20.   
  21.         window.setStatusBarColor(color);  
  22.     }  
  23.   
  24.     setContentView(R.layout.activity_main);  
  25.   
  26. }  

 

 

转载于:https://my.oschina.net/u/1177694/blog/1093975

更多相关文章

  1. 深入解析Android(安卓)declare-styleable attr style theme(中)
  2. android应用去掉title bar
  3. Android通过点击按钮改变Activity的背景颜色_个人笔记
  4. Android布局LinearLayout+RelativeLayout知识点概括
  5. Android(安卓)Studio(十):添加assets目录
  6. Android中的 animation
  7. Android(安卓)WebView加载H5音视频自动播放、关闭Activity停止播
  8. Android(安卓)Property Animation属性动画初识:位移translation(3)
  9. Android原生项目引入最新的React Native包

随机推荐

  1. Android(安卓)浅析 ContentProvider (三)
  2. Zxing图片拉伸解决 Android(安卓)二维码
  3. Android(安卓)broadcast 相同优先级的顺
  4. listview中的item滚动变黑的原因和解决办
  5. Android实战——简单网络视频播放器
  6. 四种清单中 launchMode(启动模式)解释
  7. WireX:Android智能手机组成的DDoS僵尸网络
  8. Android(安卓)animation summary
  9. android: 后台执行的定时任务
  10. Android实现本地手机数据库存储数据最简