- 设置状态栏颜色
StatusBarUtil.setColor(Activity activity, int color)
- 设置状态栏半透明
StatusBarUtil.setTranslucent(Activity activity, int statusBarAlpha)
//通过传入 statusBarAlpha 参数,可以改变状态栏的透明度值,默认值是112。
- 设置状态栏全透明
StatusBarUtil.setTransparent(Activity activity)
- 为使用 ImageView 作为头部的界面设置状态栏透明
StatusBarUtil.setTranslucentForImageView(Activity activity, int statusBarAlpha, View needOffsetView)
========================================================================
是不是已经有了明显改善,但是上面还有一块颜色格格不入
沉浸式状态栏,既可以把颜色实现沉浸,又可以把图片实现沉浸。
引入依赖
implementation ‘com.jaeger.statusbarutil:library:1.5.1’
未设置颜色沉浸的状态:
核心代码:
StatusBarUtil.setColor(MainActivity.this,getResources().getColor(R.color.bisque),0);
设置完成后的状态栏:
========================================================================
未沉浸之前的效果:
设置完成后的状态栏:
核心代码:
StatusBarUtil.setTranslucentForImageView(this, 0, constraintLayout);
MainActivity代码
public class MainActivity extends AppCompatActivity {
ConstraintLayout constraintLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
constraintLayout=findViewById(R.id.constraintlayout);
StatusBarUtil.setTranslucentForImageView(this, 0, constraintLayout);
}
}
XML代码
<?xml version="1.0" encoding="utf-8"?><androidx.constraintlayout.widget.ConstraintLayout xmlns:android=“http://schemas.android.com/apk/res/android”
xmlns:app=“http://schemas.android.com/apk/res-auto”
xmlns:tools=“http://schemas.android.com/tools”
android:layout_width=“match_parent”
android:layout_height=“match_parent”
tools:context=“.MainActivity”>
<ImageView
android:id=“@+id/imageView3”
android:layout_width=“match_parent”
android:layout_height=“300dp”
app:layout_constraintEnd_toEndOf=“parent”
app:layout_constraintStart_toStartOf=“parent”
最后
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长,自己不成体系的自学效果低效漫长且无助。
因此我收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点!不论你是刚入门Android开发的新手,还是希望在技术上不断提升的资深开发者,这些资料都将为你打开新的学习之门
如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
%以上Android开发知识点!不论你是刚入门Android开发的新手,还是希望在技术上不断提升的资深开发者,这些资料都将为你打开新的学习之门**
如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!