如何将渐变应用于Android中的状态栏? [英] How to apply gradient to status bar in android?

查看:112
本文介绍了如何将渐变应用于Android中的状态栏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人能帮我解决下图吗?由于我必须将渐变应用于状态栏.我知道只能通过它们对状态栏进行单色colorPimaryDark.

Could anybody help me out with following image. As I have to apply gradient to status bar. I know to do only single color to status bar through them colorPimaryDark.

您可以在图像中看到,它在状态栏中显示的梯度与验证布局中的梯度相同.

As you can see in Image it shows same gradient in status bar as in verification layout.

谢谢

推荐答案

您的oncreate应该像这样

Your oncreate should be like this

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        Window w = getWindow();
        w.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
        w.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
    }
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

布局文件应该是这样的.

The Layout File should be like this.

<?xml version="1.0" encoding="utf-8"?>
<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="#fff"
    tools:context="sslwireless.com.testfullscreen.MainActivity">

    <!--RePresent Toolbar-->
    <LinearLayout
        android:orientation="horizontal"
        android:background="@drawable/gradient"
        android:layout_width="match_parent"
        android:layout_height="100dp">

        <ImageView
            android:layout_gravity="center_vertical"
            android:src="@drawable/ic_arrow_back_white_24dp"
            android:layout_marginLeft="10dp"
            android:layout_width="35dp"
            android:layout_height="35dp" />

        <TextView
            android:layout_gravity="center_vertical"
            android:textSize="25sp"
            android:gravity="center_horizontal"
            android:textColor="#fff"
            android:text="Test Title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </LinearLayout>


</RelativeLayout>

渐变文件如下所示.

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient android:angle="135" android:startColor="#f56f2c" android:endColor="#fa9f46"/>
</shape>

用户界面将如下所示.

The ui will be look like this .

这篇关于如何将渐变应用于Android中的状态栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆