Translucent System Bar

小米应用商店和内置的天气软件截图如下,我们可以看到顶部的通知栏和界面色调融为一体。这种bar称为Translucent System Bar

                                                          

下面就对应实现这两种效果


第一种方式:

1、 在values、values-v19、values-v21的style.xml都设置一个 Translucent System Bar 风格的Theme


value/style.xml

<style name="ImageTranslucentTheme" parent="android:Theme.Light">
        <!-- 在Android 4.4之前的版本上运行,直接跟随系统主题 -->
		
</style>


value-19/style.xml

<style name="ImageTranslucentTheme" parent="android:Theme.Holo.Light.DarkActionBar">
        <item name="android:windowTranslucentStatus">true</item>
        <item name="android:windowTranslucentNavigation">true</item>
</style>


value-21/style.xml

<style name="ImageTranslucentTheme" parent="android:Theme.Holo.Light.DarkActionBar">
        <item name="android:windowTranslucentStatus">true</item>
        <item name="android:windowTranslucentNavigation">true</item>
        <!-- Android 5.x开始需要把颜色设置透明,否则导航栏会呈现系统默认的浅灰色 -->
        <item name="android:statusBarColor">@android:color/transparent</item>
</style>

2、在AndroidManifest.xml中对指定Activity的theme进行设置

<activity
    android:name=".MainActivity"
    android:label="@string/app_name"
    android:theme="@style/ImageTranslucentTheme" >
      
</activity>

3、在Activity的布局文件中设置背景图片,同时,需要把android:fitsSystemWindows设置为true

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/site"
    android:fitsSystemWindows="true"
    tools:context="${relativePackage}.${activityClass}" >

</RelativeLayout>

运行效果如下:


第二种方式:

1、其他设置不变,在Activity的布局文件中设置根布局背景颜色和标题栏的颜色

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FF7B35"
    android:fitsSystemWindows="true"
    android:orientation="vertical"
    tools:context="${relativePackage}.${activityClass}" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:background="#FF7B35" >
        
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="JYY"
            android:textColor="@android:color/white"
            android:textSize="25dp" />
        
    </RelativeLayout>
    
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="#F0F0F0" >
        
    </RelativeLayout>
    
</LinearLayout>

运行效果如下:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值