美文网首页
仿QQ状态栏和工具栏渐变色

仿QQ状态栏和工具栏渐变色

作者: 酷泡泡 | 来源:发表于2017-10-14 20:18 被阅读0次

    借助大虾的控件

    https://github.com/gyf-dev/ImmersionBar

    compile 'com.gyf.barlibrary:barlibrary:2.3.0'

    Paste_Image.png

    1. 布局文件

    <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    
            <!--解决状态栏与工具栏重叠的hack-->
            <View
                android:id="@+id/bar_0_view"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:background="@drawable/toolbar_shape" />
    
            <!--顶部工具栏-->
            <!--android:background="@drawable/toolbar_shape"-->
            <android.support.v7.widget.Toolbar
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:id="@+id/main_bar"
                app:title="@string/main">
            </android.support.v7.widget.Toolbar>
    

    2. toolbar_shape.xml

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

    3. 代码

        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            ImmersionBar.with(this)
                    .statusBarView(R.id.bar_0_view)
                    .init();
    (省略...)
    }
    

    转载请注明:http://www.jianshu.com/p/6188c2e808c9

    相关文章

      网友评论

          本文标题:仿QQ状态栏和工具栏渐变色

          本文链接:https://www.haomeiwen.com/subject/gcufuxtx.html