温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Java怎么实现渐变色沉浸式状态栏

发布时间:2021-10-29 17:21:21 来源:亿速云 阅读:293 作者:iii 栏目:编程语言

这篇文章主要介绍“Java怎么实现渐变色沉浸式状态栏”,在日常操作中,相信很多人在Java怎么实现渐变色沉浸式状态栏问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”Java怎么实现渐变色沉浸式状态栏”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

在AndroidManifest.xml中的activity中使用自定义主题
<activity android:name=".dailyAccompany.view.activity.AlarmListActivity"
    android:theme="@style/TranslucentStatusTheme"
    android:screenOrientation="portrait">
</activity>

然后在style.xml中去定义该主题

values的styles.xml

<!--透明状态栏-->
<style name="TranslucentStatusTheme" parent="Theme.AppCompat.Light.NoActionBar">
 
</style>

values-v19的styles.xml

<style name="TranslucentStatusTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowTranslucentStatus">true</item>
    <item name="android:windowTranslucentNavigation">true</item>
</style>

values-v21的styles.xml

<style name="TranslucentStatusTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowTranslucentStatus">false</item>
    <item name="android:windowTranslucentNavigation">true</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
</style>

在布局文件中的第一个控件设置为渐变

<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/alarm_shade_bg"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools">
 
    <ImageView
        android:id="@+id/alarm_top"
        android:layout_width="match_parent"
        android:layout_height="64dp"
        android:background="@drawable/title_shade_bule"/>

   省略中间布局。。。。。。。。。。。。。。。。。。

</android.support.constraint.ConstraintLayout>

然后去定义渐变布局title_shade_bule

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient
        android:angle="180"
        android:centerColor="#2798f0"
        android:endColor="#6043ce"
        android:startColor="#6043ce"
        android:type="linear" />
</shape>

就可以实现了

注:如果顶部是使用Toolbar,需要在Toolbar中加上

android:fitsSystemWindows="true"

到此,关于“Java怎么实现渐变色沉浸式状态栏”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI