├── .gitignore
├── .idea
├── .name
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── gradle.xml
├── misc.xml
├── modules.xml
└── runConfigurations.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── hankkin
│ │ └── gradationtitlebar
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── hankkin
│ │ │ └── gradationtitlebar
│ │ │ ├── BannerActivity.java
│ │ │ ├── MainActivity.java
│ │ │ └── QQSpeakActivity.java
│ └── res
│ │ ├── drawable-xhdpi
│ │ ├── banner1.png
│ │ ├── banner2.png
│ │ ├── banner3.png
│ │ └── banner4.png
│ │ ├── layout
│ │ ├── activity_banner.xml
│ │ ├── activity_main.xml
│ │ └── activity_qqspeak.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ ├── styleable.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── hankkin
│ └── gradationtitlebar
│ └── ExampleUnitTest.java
├── build.gradle
├── gradationscroll
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── hankkin
│ │ └── gradationscroll
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── hankkin
│ │ │ └── gradationscroll
│ │ │ ├── GradationScrollView.java
│ │ │ ├── MaterialIndicator.java
│ │ │ ├── NoScrollListview.java
│ │ │ └── StatusBarUtil.java
│ └── res
│ │ └── values
│ │ ├── strings.xml
│ │ ├── styleable.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── hankkin
│ └── gradationscroll
│ └── ExampleUnitTest.java
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 |
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | GradationTitleBar
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
25 |
26 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # GradationTitleBar
2 | 仿QQ空间标题栏渐变
3 | ###look at the screenshot:
4 |
5 |
6 |
7 | ###xml
8 | ```java
9 |
10 |
15 |
16 |
21 |
25 |
31 |
35 |
36 |
37 |
38 |
48 |
49 | ```
50 | ###获取顶部图片高度后,设置滚动监听
51 | ```java
52 | private void initListeners() {
53 |
54 | ViewTreeObserver vto = ivBanner.getViewTreeObserver();
55 | vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
56 | @Override
57 | public void onGlobalLayout() {
58 | textView.getViewTreeObserver().removeGlobalOnLayoutListener(
59 | this);
60 | height = ivBanner.getHeight();
61 |
62 | scrollView.setScrollViewListener(QQSpeakActivity.this);
63 | }
64 | });
65 | }
66 | ```
67 | ###滑动监听,设置透明度
68 | ```java
69 | @Override
70 | public void onScrollChanged(GradationScrollView scrollView, int x, int y,
71 | int oldx, int oldy) {
72 | // TODO Auto-generated method stub
73 | if (y <= 0) { //设置标题的背景颜色
74 | textView.setBackgroundColor(Color.argb((int) 0, 144,151,166));
75 | } else if (y > 0 && y <= height) { //滑动距离小于banner图的高度时,设置背景和字体颜色颜色透明度渐变
76 | float scale = (float) y / height;
77 | float alpha = (255 * scale);
78 | textView.setTextColor(Color.argb((int) alpha, 255,255,255));
79 | textView.setBackgroundColor(Color.argb((int) alpha, 144,151,166));
80 | } else { //滑动到banner下面设置普通颜色
81 | textView.setBackgroundColor(Color.argb((int) 255, 144,151,166));
82 | }
83 | }
84 | ```
85 | ###博客地址
86 | ---------------------------
87 |
88 |
89 | ###License
90 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.2"
6 |
7 | defaultConfig {
8 | applicationId "com.hankkin.gradationtitlebar"
9 | minSdkVersion 15
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(include: ['*.jar'], dir: 'libs')
24 | testCompile 'junit:junit:4.12'
25 | compile 'com.android.support:appcompat-v7:23.4.0'
26 | compile project(':gradationscroll')
27 | }
28 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/Hankkin/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/hankkin/gradationtitlebar/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.hankkin.gradationtitlebar;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hankkin/gradationtitlebar/BannerActivity.java:
--------------------------------------------------------------------------------
1 | package com.hankkin.gradationtitlebar;
2 |
3 | import android.graphics.Color;
4 | import android.support.v4.view.PagerAdapter;
5 | import android.support.v4.view.ViewPager;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.os.Bundle;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.view.ViewTreeObserver;
11 | import android.view.Window;
12 | import android.widget.ArrayAdapter;
13 | import android.widget.ImageView;
14 | import android.widget.ListView;
15 | import android.widget.TextView;
16 |
17 | import com.hankkin.gradationscroll.GradationScrollView;
18 | import com.hankkin.gradationscroll.MaterialIndicator;
19 | import com.hankkin.gradationscroll.StatusBarUtil;
20 |
21 | public class BannerActivity extends AppCompatActivity implements GradationScrollView.ScrollViewListener {
22 | private GradationScrollView scrollView;
23 | private ListView listView;
24 | private TextView textView;
25 | private int imageHeight;
26 | private ViewPager viewPager;
27 | @Override
28 | protected void onCreate(Bundle savedInstanceState) {
29 | super.onCreate(savedInstanceState);
30 | getWindow().requestFeature(Window.FEATURE_NO_TITLE);
31 | StatusBarUtil.setImgTransparent(this);
32 | setContentView(R.layout.activity_banner);
33 |
34 | scrollView = (GradationScrollView) findViewById(R.id.scrollview);
35 | listView = (ListView) findViewById(R.id.listview);
36 | textView = (TextView) findViewById(R.id.textview);
37 | viewPager = (ViewPager) findViewById(R.id.viewPager);
38 |
39 | viewPager.setFocusable(true);
40 | viewPager.setFocusableInTouchMode(true);
41 | viewPager.requestFocus();
42 |
43 | MaterialIndicator indicator = (MaterialIndicator) findViewById(R.id.indicator);
44 | ViewPager viewPager = (ViewPager) findViewById(R.id.viewPager);
45 | viewPager.setAdapter(new MyPagerAdapter());
46 | viewPager.addOnPageChangeListener(indicator);
47 | indicator.setAdapter(viewPager.getAdapter());
48 |
49 | initListeners();
50 | initData();
51 | }
52 |
53 | /**
54 | * viewpager适配器
55 | */
56 | private class MyPagerAdapter extends PagerAdapter {
57 | public int[] drawables = {R.drawable.banner1
58 | ,R.drawable.banner2,R.drawable.banner3,R.drawable.banner4};
59 | @Override
60 | public int getCount() {
61 | return 4;
62 | }
63 |
64 | @Override
65 | public boolean isViewFromObject(View view, Object object) {
66 | return object == view;
67 | }
68 |
69 | @Override
70 | public Object instantiateItem(ViewGroup container, int position) {
71 | ImageView view = new ImageView(container.getContext());
72 | view.setImageResource(drawables[position]);
73 | view.setScaleType(ImageView.ScaleType.FIT_XY);
74 | container.addView(view);
75 | return view;
76 | }
77 |
78 | @Override
79 | public void destroyItem(ViewGroup container, int position, Object object) {
80 | container.removeView(((View) object));
81 | }
82 | }
83 |
84 | /**
85 | * 获取顶部图片高度后,设置滚动监听
86 | */
87 | private void initListeners() {
88 |
89 | ViewTreeObserver vto = viewPager.getViewTreeObserver();
90 | vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
91 | @Override
92 | public void onGlobalLayout() {
93 | viewPager.getViewTreeObserver().removeGlobalOnLayoutListener(
94 | this);
95 | imageHeight = viewPager.getHeight();
96 |
97 | scrollView.setScrollViewListener(BannerActivity.this);
98 | }
99 | });
100 | }
101 |
102 |
103 |
104 | private void initData() {
105 | ArrayAdapter adapter = new ArrayAdapter(BannerActivity.this, android.R.layout.simple_list_item_1, getResources().getStringArray(R.array.data));
106 | listView.setAdapter(adapter);
107 | }
108 |
109 |
110 | /**
111 | * 滑动监听
112 | * @param scrollView
113 | * @param x
114 | * @param y
115 | * @param oldx
116 | * @param oldy
117 | */
118 | @Override
119 | public void onScrollChanged(GradationScrollView scrollView, int x, int y,
120 | int oldx, int oldy) {
121 | // TODO Auto-generated method stub
122 | if (y <= 0) { //设置标题的背景颜色
123 | textView.setBackgroundColor(Color.argb((int) 0, 144,151,166));
124 | } else if (y > 0 && y <= imageHeight) { //滑动距离小于banner图的高度时,设置背景和字体颜色颜色透明度渐变
125 | float scale = (float) y / imageHeight;
126 | float alpha = (255 * scale);
127 | textView.setTextColor(Color.argb((int) alpha, 255,255,255));
128 | textView.setBackgroundColor(Color.argb((int) alpha, 144,151,166));
129 | } else { //滑动到banner下面设置普通颜色
130 | textView.setBackgroundColor(Color.argb((int) 255, 144,151,166));
131 | }
132 | }
133 | }
134 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hankkin/gradationtitlebar/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.hankkin.gradationtitlebar;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.View;
7 | import android.widget.Button;
8 |
9 | public class MainActivity extends AppCompatActivity{
10 |
11 | Button btnQQ;
12 | Button btnBanner;
13 |
14 | @Override
15 | protected void onCreate(Bundle savedInstanceState) {
16 | super.onCreate(savedInstanceState);
17 |
18 | setContentView(R.layout.activity_main);
19 |
20 | btnQQ = (Button) findViewById(R.id.btn_qq);
21 | btnBanner = (Button) findViewById(R.id.btn_banner);
22 |
23 | btnQQ.setOnClickListener(new View.OnClickListener() {
24 | @Override
25 | public void onClick(View v) {
26 | Intent intent = new Intent(MainActivity.this,QQSpeakActivity.class);
27 | startActivity(intent);
28 | }
29 | });
30 |
31 | btnBanner.setOnClickListener(new View.OnClickListener() {
32 | @Override
33 | public void onClick(View v) {
34 | Intent intent = new Intent(MainActivity.this,BannerActivity.class);
35 | startActivity(intent);
36 | }
37 | });
38 |
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hankkin/gradationtitlebar/QQSpeakActivity.java:
--------------------------------------------------------------------------------
1 | package com.hankkin.gradationtitlebar;
2 |
3 | import android.graphics.Color;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.os.Bundle;
6 | import android.view.ViewTreeObserver;
7 | import android.view.Window;
8 | import android.widget.ArrayAdapter;
9 | import android.widget.ImageView;
10 | import android.widget.ListView;
11 | import android.widget.TextView;
12 |
13 | import com.hankkin.gradationscroll.GradationScrollView;
14 | import com.hankkin.gradationscroll.StatusBarUtil;
15 |
16 | public class QQSpeakActivity extends AppCompatActivity implements GradationScrollView.ScrollViewListener{
17 | private GradationScrollView scrollView;
18 |
19 | private ListView listView;
20 |
21 | private TextView textView;
22 | private int height;
23 | private ImageView ivBanner;
24 |
25 | @Override
26 | protected void onCreate(Bundle savedInstanceState) {
27 | super.onCreate(savedInstanceState);
28 | getWindow().requestFeature(Window.FEATURE_NO_TITLE);
29 | StatusBarUtil.setImgTransparent(this);
30 | setContentView(R.layout.activity_qqspeak);
31 |
32 | scrollView = (GradationScrollView) findViewById(R.id.scrollview);
33 | listView = (ListView) findViewById(R.id.listview);
34 | textView = (TextView) findViewById(R.id.textview);
35 | ivBanner = (ImageView) findViewById(R.id.iv_banner);
36 |
37 | ivBanner.setFocusable(true);
38 | ivBanner.setFocusableInTouchMode(true);
39 | ivBanner.requestFocus();
40 |
41 | initListeners();
42 | initData();
43 | }
44 |
45 | /**
46 | * 获取顶部图片高度后,设置滚动监听
47 | */
48 | private void initListeners() {
49 |
50 | ViewTreeObserver vto = ivBanner.getViewTreeObserver();
51 | vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
52 | @Override
53 | public void onGlobalLayout() {
54 | textView.getViewTreeObserver().removeGlobalOnLayoutListener(
55 | this);
56 | height = ivBanner.getHeight();
57 |
58 | scrollView.setScrollViewListener(QQSpeakActivity.this);
59 | }
60 | });
61 | }
62 |
63 |
64 |
65 | private void initData() {
66 | ArrayAdapter adapter = new ArrayAdapter(QQSpeakActivity.this, android.R.layout.simple_list_item_1, getResources().getStringArray(R.array.data));
67 | listView.setAdapter(adapter);
68 | }
69 |
70 |
71 | /**
72 | * 滑动监听
73 | * @param scrollView
74 | * @param x
75 | * @param y
76 | * @param oldx
77 | * @param oldy
78 | */
79 | @Override
80 | public void onScrollChanged(GradationScrollView scrollView, int x, int y,
81 | int oldx, int oldy) {
82 | // TODO Auto-generated method stub
83 | if (y <= 0) { //设置标题的背景颜色
84 | textView.setBackgroundColor(Color.argb((int) 0, 144,151,166));
85 | } else if (y > 0 && y <= height) { //滑动距离小于banner图的高度时,设置背景和字体颜色颜色透明度渐变
86 | float scale = (float) y / height;
87 | float alpha = (255 * scale);
88 | textView.setTextColor(Color.argb((int) alpha, 255,255,255));
89 | textView.setBackgroundColor(Color.argb((int) alpha, 144,151,166));
90 | } else { //滑动到banner下面设置普通颜色
91 | textView.setBackgroundColor(Color.argb((int) 255, 144,151,166));
92 | }
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/banner1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hankkin/GradationTitleBar/edb820965d82a1db379d915f10bee996f11fda8f/app/src/main/res/drawable-xhdpi/banner1.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/banner2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hankkin/GradationTitleBar/edb820965d82a1db379d915f10bee996f11fda8f/app/src/main/res/drawable-xhdpi/banner2.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/banner3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hankkin/GradationTitleBar/edb820965d82a1db379d915f10bee996f11fda8f/app/src/main/res/drawable-xhdpi/banner3.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/banner4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hankkin/GradationTitleBar/edb820965d82a1db379d915f10bee996f11fda8f/app/src/main/res/drawable-xhdpi/banner4.png
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_banner.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
19 |
20 |
25 |
26 |
36 |
37 |
41 |
42 |
43 |
44 |
45 |
55 |
56 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
17 |
18 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_qqspeak.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
17 |
23 |
27 |
28 |
29 |
30 |
40 |
41 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hankkin/GradationTitleBar/edb820965d82a1db379d915f10bee996f11fda8f/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hankkin/GradationTitleBar/edb820965d82a1db379d915f10bee996f11fda8f/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hankkin/GradationTitleBar/edb820965d82a1db379d915f10bee996f11fda8f/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hankkin/GradationTitleBar/edb820965d82a1db379d915f10bee996f11fda8f/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hankkin/GradationTitleBar/edb820965d82a1db379d915f10bee996f11fda8f/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #9097A6
4 | #9097A6
5 | #9097A6
6 | #00000000
7 | #FFFFFF
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | GradationTitleBar
3 |
4 | - 我是第一行数据
5 | - 我是第二行数据
6 | - 我是第二行数据
7 | - 我是第二行数据
8 | - 我是第二行数据
9 | - 我是第二行数据
10 | - 我是第二行数据
11 | - 我是第二行数据
12 | - 我是第二行数据
13 | - 我是第二行数据
14 | - 我是第二行数据
15 | - 我是第二行数据
16 | - 我是第二行数据
17 | - 我是第二行数据
18 | - 我是第二行数据
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styleable.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
13 |
18 |
19 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/app/src/test/java/com/hankkin/gradationtitlebar/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.hankkin.gradationtitlebar;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.1.2'
9 | classpath 'com.novoda:bintray-release:0.3.4'
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/gradationscroll/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/gradationscroll/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | //apply plugin: 'com.novoda.bintray-release'//添加
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.2"
6 |
7 | defaultConfig {
8 | minSdkVersion 15
9 | targetSdkVersion 23
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile fileTree(dir: 'libs', include: ['*.jar'])
23 | testCompile 'junit:junit:4.12'
24 | compile 'com.android.support:appcompat-v7:23.4.0'
25 | }
26 | //添加
27 | //publish {
28 | // userOrg = 'huang'//bintray.com用户名
29 | // groupId = 'com.hankkin'//jcenter上的路径
30 | // artifactId = 'gradation'//项目名称
31 | // publishVersion = '1.0.1'//版本号
32 | // desc = '放QQ动态标题栏渐变'//描述,不重要
33 | // website = 'https://github.com/Hankkin/SwipeRefreshDemo'//网站,不重要
34 | //}
--------------------------------------------------------------------------------
/gradationscroll/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/Hankkin/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/gradationscroll/src/androidTest/java/com/hankkin/gradationscroll/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.hankkin.gradationscroll;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/gradationscroll/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/gradationscroll/src/main/java/com/hankkin/gradationscroll/GradationScrollView.java:
--------------------------------------------------------------------------------
1 | package com.hankkin.gradationscroll;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.widget.ScrollView;
6 | /**
7 | * 带滚动监听的scrollview
8 | *
9 | */
10 | public class GradationScrollView extends ScrollView {
11 |
12 | public interface ScrollViewListener {
13 |
14 | void onScrollChanged(GradationScrollView scrollView, int x, int y,
15 | int oldx, int oldy);
16 |
17 | }
18 |
19 | private ScrollViewListener scrollViewListener = null;
20 |
21 | public GradationScrollView(Context context) {
22 | super(context);
23 | }
24 |
25 | public GradationScrollView(Context context, AttributeSet attrs,
26 | int defStyle) {
27 | super(context, attrs, defStyle);
28 | }
29 |
30 | public GradationScrollView(Context context, AttributeSet attrs) {
31 | super(context, attrs);
32 | }
33 |
34 | public void setScrollViewListener(ScrollViewListener scrollViewListener) {
35 | this.scrollViewListener = scrollViewListener;
36 | }
37 |
38 | @Override
39 | protected void onScrollChanged(int x, int y, int oldx, int oldy) {
40 | super.onScrollChanged(x, y, oldx, oldy);
41 | if (scrollViewListener != null) {
42 | scrollViewListener.onScrollChanged(this, x, y, oldx, oldy);
43 | }
44 | }
45 |
46 | }
--------------------------------------------------------------------------------
/gradationscroll/src/main/java/com/hankkin/gradationscroll/MaterialIndicator.java:
--------------------------------------------------------------------------------
1 | package com.hankkin.gradationscroll;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Canvas;
6 | import android.graphics.Color;
7 | import android.graphics.Paint;
8 | import android.graphics.RectF;
9 | import android.support.v4.view.PagerAdapter;
10 | import android.support.v4.view.ViewCompat;
11 | import android.support.v4.view.ViewPager;
12 | import android.support.v4.view.animation.FastOutSlowInInterpolator;
13 | import android.util.AttributeSet;
14 | import android.view.View;
15 | import android.view.animation.Interpolator;
16 |
17 | public class MaterialIndicator extends View implements ViewPager.OnPageChangeListener {
18 |
19 | private static final String TAG = MaterialIndicator.class.getSimpleName();
20 | private static final int UNDEFINED_PADDING = -1;
21 | private final Interpolator interpolator = new FastOutSlowInInterpolator();
22 | private final Paint indicatorPaint;
23 | private final Paint selectedIndicatorPaint;
24 | private final float indicatorRadius;
25 | private final float indicatorPadding;
26 |
27 | private final RectF selectorRect;
28 | private int count;
29 | private int selectedPage = 0;
30 | private float deselectedAlpha = 0.2f;
31 | private float offset;
32 |
33 | public MaterialIndicator(Context context, AttributeSet attrs) {
34 | this(context, attrs, 0);
35 | }
36 |
37 | public MaterialIndicator(Context context, AttributeSet attrs, int defStyleAttr) {
38 | super(context, attrs, defStyleAttr);
39 | selectedIndicatorPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
40 | indicatorPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
41 | indicatorPaint.setColor(Color.BLACK);
42 | indicatorPaint.setAlpha((int) (deselectedAlpha * 255));
43 | selectorRect = new RectF();
44 | if (isInEditMode()) {
45 | count = 3;
46 | }
47 | TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MaterialIndicator, 0, R.style.MaterialIndicator);
48 | try {
49 | indicatorRadius = typedArray.getDimension(R.styleable.MaterialIndicator_mi_indicatorRadius, 0);
50 | indicatorPadding = typedArray.getDimension(R.styleable.MaterialIndicator_mi_indicatorPadding, UNDEFINED_PADDING);
51 | selectedIndicatorPaint.setColor(typedArray.getColor(R.styleable.MaterialIndicator_mi_indicatorColor, 0));
52 | } finally {
53 | typedArray.recycle();
54 | }
55 | }
56 |
57 | @Override
58 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
59 | selectedPage = position;
60 | offset = positionOffset;
61 | invalidate();
62 | }
63 |
64 | @Override
65 | public void onPageSelected(int position) {
66 | selectedPage = position;
67 | offset = 0;
68 | invalidate();
69 | }
70 |
71 | @Override
72 | public void onPageScrollStateChanged(int state) {
73 |
74 | }
75 |
76 | public void setAdapter(PagerAdapter adapter) {
77 | this.count = adapter.getCount();
78 | requestLayout();
79 | invalidate();
80 | }
81 |
82 | @Override
83 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
84 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
85 | int width = getMeasuredWidth();
86 | if (getLayoutParams().width == ViewPager.LayoutParams.WRAP_CONTENT) {
87 | width = getSuggestedMinimumWidth();
88 | }
89 | setMeasuredDimension(width, getSuggestedMinimumHeight());
90 | }
91 |
92 | @Override
93 | protected int getSuggestedMinimumWidth() {
94 | return (int) (indicatorDiameter() * count + getInternalPadding());
95 | }
96 |
97 | private float getInternalPadding() {
98 | if (indicatorPadding == UNDEFINED_PADDING || indicatorPadding == 0 || count == 0) {
99 | return 0;
100 | }
101 | return indicatorPadding * (count - 1);
102 | }
103 |
104 | @Override
105 | protected int getSuggestedMinimumHeight() {
106 | return getPaddingTop() + getPaddingBottom() + (int) indicatorDiameter();
107 | }
108 |
109 | @Override
110 | protected void onDraw(Canvas canvas) {
111 | super.onDraw(canvas);
112 | float gap = getGapBetweenIndicators();
113 | for (int i = 0; i < count; i++) {
114 | float position = indicatorStartX(gap, i);
115 | canvas.drawCircle(position + indicatorRadius, midY(), indicatorRadius, indicatorPaint);
116 | }
117 | float extenderStart = indicatorStartX(gap, selectedPage) + Math.max(gap * (interpolatedOffset() - 0.5f) * 2, 0);
118 | float extenderEnd = indicatorStartX(gap, selectedPage) + indicatorDiameter() + Math.min(gap * interpolatedOffset() * 2, gap);
119 | selectorRect.set(extenderStart, midY() - indicatorRadius, extenderEnd, midY() + indicatorRadius);
120 | canvas.drawRoundRect(selectorRect, indicatorRadius, indicatorRadius, selectedIndicatorPaint);
121 | }
122 |
123 | private float getGapBetweenIndicators() {
124 | if (indicatorPadding == UNDEFINED_PADDING) {
125 | return (getWidth() - indicatorDiameter()) / (count + 1);
126 | } else {
127 | return indicatorPadding;
128 | }
129 | }
130 |
131 | private float indicatorStartX(float gap, int page) {
132 | return ViewCompat.getPaddingStart(this) + gap * page + indicatorRadius;
133 | }
134 |
135 | private float interpolatedOffset() {
136 | return interpolator.getInterpolation(offset);
137 | }
138 |
139 | private float indicatorDiameter() {
140 | return indicatorRadius * 2;
141 | }
142 |
143 | private float midY() {
144 | return getHeight() / 2f;
145 | }
146 |
147 | }
148 |
--------------------------------------------------------------------------------
/gradationscroll/src/main/java/com/hankkin/gradationscroll/NoScrollListview.java:
--------------------------------------------------------------------------------
1 | package com.hankkin.gradationscroll;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.widget.ListView;
6 |
7 | public class NoScrollListview extends ListView {
8 |
9 | public NoScrollListview(Context context) {
10 | // TODO Auto-generated method stub
11 | super(context);
12 | }
13 |
14 | public NoScrollListview(Context context, AttributeSet attrs) {
15 | // TODO Auto-generated method stub
16 | super(context, attrs);
17 | }
18 |
19 | public NoScrollListview(Context context, AttributeSet attrs, int defStyle) {
20 | // TODO Auto-generated method stub
21 | super(context, attrs, defStyle);
22 | }
23 |
24 | @Override
25 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
26 | // TODO Auto-generated method stub
27 | int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
28 | MeasureSpec.AT_MOST);
29 | super.onMeasure(widthMeasureSpec, expandSpec);
30 | }
31 | }
--------------------------------------------------------------------------------
/gradationscroll/src/main/java/com/hankkin/gradationscroll/StatusBarUtil.java:
--------------------------------------------------------------------------------
1 | package com.hankkin.gradationscroll;
2 |
3 | import android.annotation.TargetApi;
4 | import android.app.Activity;
5 | import android.content.Context;
6 | import android.graphics.Color;
7 | import android.os.Build;
8 | import android.support.v4.widget.DrawerLayout;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.view.Window;
12 | import android.view.WindowManager;
13 | import android.widget.LinearLayout;
14 |
15 | /**
16 | * Created by Jaeger on 16/2/14.
17 | *
18 | * Email: chjie.jaeger@gamil.com
19 | * GitHub: https://github.com/laobie
20 | */
21 | public class StatusBarUtil {
22 |
23 | public static final int DEFAULT_STATUS_BAR_ALPHA = 112;
24 |
25 | /**
26 | * 设置状态栏颜色
27 | *
28 | * @param activity 需要设置的 activity
29 | * @param color 状态栏颜色值
30 | */
31 | public static void setColor(Activity activity, int color) {
32 | setColor(activity, color, DEFAULT_STATUS_BAR_ALPHA);
33 | }
34 |
35 | /**
36 | * 设置状态栏颜色
37 | *
38 | * @param activity 需要设置的activity
39 | * @param color 状态栏颜色值
40 | * @param statusBarAlpha 状态栏透明度
41 | */
42 | public static void setColor(Activity activity, int color, int statusBarAlpha) {
43 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
44 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
45 | activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
46 | activity.getWindow().setStatusBarColor(calculateStatusColor(color, statusBarAlpha));
47 | } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
48 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
49 | // 生成一个状态栏大小的矩形
50 | View statusView = createStatusBarView(activity, color, statusBarAlpha);
51 | // 添加 statusView 到布局中
52 | ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
53 | decorView.addView(statusView);
54 | setRootView(activity);
55 | }
56 | }
57 |
58 | /**
59 | * 设置状态栏纯色 不加半透明效果
60 | *
61 | * @param activity 需要设置的 activity
62 | * @param color 状态栏颜色值
63 | */
64 | public static void setColorNoTranslucent(Activity activity, int color) {
65 | setColor(activity, color, 0);
66 | }
67 |
68 | /**
69 | * 设置状态栏颜色(5.0以下无半透明效果,不建议使用)
70 | *
71 | * @param activity 需要设置的 activity
72 | * @param color 状态栏颜色值
73 | */
74 | public static void setColorDiff(Activity activity, int color) {
75 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
76 | return;
77 | }
78 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
79 | // 生成一个状态栏大小的矩形
80 | View statusView = createStatusBarView(activity, color);
81 | // 添加 statusView 到布局中
82 | ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
83 | decorView.addView(statusView);
84 | setRootView(activity);
85 | }
86 |
87 | /**
88 | * 使状态栏半透明
89 | *
90 | * 适用于图片作为背景的界面,此时需要图片填充到状态栏
91 | *
92 | * @param activity 需要设置的activity
93 | */
94 | public static void setTranslucent(Activity activity) {
95 | setTranslucent(activity, DEFAULT_STATUS_BAR_ALPHA);
96 | }
97 |
98 | /**
99 | * 使状态栏半透明
100 | *
101 | * 适用于图片作为背景的界面,此时需要图片填充到状态栏
102 | *
103 | * @param activity 需要设置的activity
104 | * @param statusBarAlpha 状态栏透明度
105 | */
106 | public static void setTranslucent(Activity activity, int statusBarAlpha) {
107 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
108 | return;
109 | }
110 | setTransparent(activity);
111 | addTranslucentView(activity, statusBarAlpha);
112 | }
113 |
114 | /**
115 | * 设置状态栏全透明
116 | *
117 | * @param activity 需要设置的activity
118 | */
119 | public static void setTransparent(Activity activity) {
120 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
121 | return;
122 | }
123 | transparentStatusBar(activity);
124 | setRootView(activity);
125 | }
126 |
127 | /**
128 | * 使状态栏透明(5.0以上半透明效果,不建议使用)
129 | *
130 | * 适用于图片作为背景的界面,此时需要图片填充到状态栏
131 | *
132 | * @param activity 需要设置的activity
133 | */
134 | public static void setTranslucentDiff(Activity activity) {
135 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
136 | // 设置状态栏透明
137 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
138 | setRootView(activity);
139 | }
140 | }
141 |
142 | /**
143 | * 为DrawerLayout 布局设置状态栏变色
144 | *
145 | * @param activity 需要设置的activity
146 | * @param drawerLayout DrawerLayout
147 | * @param color 状态栏颜色值
148 | */
149 | public static void setColorForDrawerLayout(Activity activity, DrawerLayout drawerLayout, int color) {
150 | setColorForDrawerLayout(activity, drawerLayout, color, DEFAULT_STATUS_BAR_ALPHA);
151 | }
152 |
153 | /**
154 | * 为DrawerLayout 布局设置状态栏颜色,纯色
155 | *
156 | * @param activity 需要设置的activity
157 | * @param drawerLayout DrawerLayout
158 | * @param color 状态栏颜色值
159 | */
160 | public static void setColorNoTranslucentForDrawerLayout(Activity activity, DrawerLayout drawerLayout, int color) {
161 | setColorForDrawerLayout(activity, drawerLayout, color, 0);
162 | }
163 |
164 | /**
165 | * 为DrawerLayout 布局设置状态栏变色
166 | *
167 | * @param activity 需要设置的activity
168 | * @param drawerLayout DrawerLayout
169 | * @param color 状态栏颜色值
170 | * @param statusBarAlpha 状态栏透明度
171 | */
172 | public static void setColorForDrawerLayout(Activity activity, DrawerLayout drawerLayout, int color, int statusBarAlpha) {
173 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
174 | return;
175 | }
176 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
177 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
178 | activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
179 | activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
180 | } else {
181 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
182 | }
183 | // 生成一个状态栏大小的矩形
184 | View statusBarView = createStatusBarView(activity, color);
185 | // 添加 statusBarView 到布局中
186 | ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
187 | contentLayout.addView(statusBarView, 0);
188 | // 内容布局不是 LinearLayout 时,设置padding top
189 | if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) {
190 | contentLayout.getChildAt(1).setPadding(0, getStatusBarHeight(activity), 0, 0);
191 | }
192 | // 设置属性
193 | ViewGroup drawer = (ViewGroup) drawerLayout.getChildAt(1);
194 | drawerLayout.setFitsSystemWindows(false);
195 | contentLayout.setFitsSystemWindows(false);
196 | contentLayout.setClipToPadding(true);
197 | drawer.setFitsSystemWindows(false);
198 |
199 | addTranslucentView(activity, statusBarAlpha);
200 | }
201 |
202 | /**
203 | * 为DrawerLayout 布局设置状态栏变色(5.0以下无半透明效果,不建议使用)
204 | *
205 | * @param activity 需要设置的activity
206 | * @param drawerLayout DrawerLayout
207 | * @param color 状态栏颜色值
208 | */
209 | public static void setColorForDrawerLayoutDiff(Activity activity, DrawerLayout drawerLayout, int color) {
210 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
211 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
212 | // 生成一个状态栏大小的矩形
213 | View statusBarView = createStatusBarView(activity, color);
214 | // 添加 statusBarView 到布局中
215 | ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
216 | contentLayout.addView(statusBarView, 0);
217 | // 内容布局不是 LinearLayout 时,设置padding top
218 | if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) {
219 | contentLayout.getChildAt(1).setPadding(0, getStatusBarHeight(activity), 0, 0);
220 | }
221 | // 设置属性
222 | ViewGroup drawer = (ViewGroup) drawerLayout.getChildAt(1);
223 | drawerLayout.setFitsSystemWindows(false);
224 | contentLayout.setFitsSystemWindows(false);
225 | contentLayout.setClipToPadding(true);
226 | drawer.setFitsSystemWindows(false);
227 | }
228 | }
229 |
230 | /**
231 | * 为 DrawerLayout 布局设置状态栏透明
232 | *
233 | * @param activity 需要设置的activity
234 | * @param drawerLayout DrawerLayout
235 | */
236 | public static void setTranslucentForDrawerLayout(Activity activity, DrawerLayout drawerLayout) {
237 | setTranslucentForDrawerLayout(activity, drawerLayout, DEFAULT_STATUS_BAR_ALPHA);
238 | }
239 |
240 | /**
241 | * 为 DrawerLayout 布局设置状态栏透明
242 | *
243 | * @param activity 需要设置的activity
244 | * @param drawerLayout DrawerLayout
245 | */
246 | public static void setTranslucentForDrawerLayout(Activity activity, DrawerLayout drawerLayout, int statusBarAlpha) {
247 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
248 | return;
249 | }
250 | setTransparentForDrawerLayout(activity, drawerLayout);
251 | addTranslucentView(activity, statusBarAlpha);
252 | }
253 |
254 | /**
255 | * 为 DrawerLayout 布局设置状态栏透明
256 | *
257 | * @param activity 需要设置的activity
258 | * @param drawerLayout DrawerLayout
259 | */
260 | public static void setTransparentForDrawerLayout(Activity activity, DrawerLayout drawerLayout) {
261 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
262 | return;
263 | }
264 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
265 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
266 | activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
267 | activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
268 | } else {
269 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
270 | }
271 |
272 | ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
273 | // 内容布局不是 LinearLayout 时,设置padding top
274 | if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) {
275 | contentLayout.getChildAt(1).setPadding(0, getStatusBarHeight(activity), 0, 0);
276 | }
277 |
278 | // 设置属性
279 | ViewGroup drawer = (ViewGroup) drawerLayout.getChildAt(1);
280 | drawerLayout.setFitsSystemWindows(false);
281 | contentLayout.setFitsSystemWindows(false);
282 | contentLayout.setClipToPadding(true);
283 | drawer.setFitsSystemWindows(false);
284 | }
285 |
286 | /**
287 | * 为 DrawerLayout 布局设置状态栏透明(5.0以上半透明效果,不建议使用)
288 | *
289 | * @param activity 需要设置的activity
290 | * @param drawerLayout DrawerLayout
291 | */
292 | public static void setTranslucentForDrawerLayoutDiff(Activity activity, DrawerLayout drawerLayout) {
293 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
294 | // 设置状态栏透明
295 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
296 | // 设置内容布局属性
297 | ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
298 | contentLayout.setFitsSystemWindows(true);
299 | contentLayout.setClipToPadding(true);
300 | // 设置抽屉布局属性
301 | ViewGroup vg = (ViewGroup) drawerLayout.getChildAt(1);
302 | vg.setFitsSystemWindows(false);
303 | // 设置 DrawerLayout 属性
304 | drawerLayout.setFitsSystemWindows(false);
305 | }
306 | }
307 |
308 | /**
309 | * 添加半透明矩形条
310 | *
311 | * @param activity 需要设置的 activity
312 | * @param statusBarAlpha 透明值
313 | */
314 | private static void addTranslucentView(Activity activity, int statusBarAlpha) {
315 | ViewGroup contentView = (ViewGroup) activity.findViewById(android.R.id.content);
316 | // 移除半透明矩形,以免叠加
317 | if (contentView.getChildCount() > 1) {
318 | contentView.removeViewAt(1);
319 | }
320 | contentView.addView(createTranslucentStatusBarView(activity, statusBarAlpha));
321 | }
322 |
323 | /**
324 | * 生成一个和状态栏大小相同的彩色矩形条
325 | *
326 | * @param activity 需要设置的 activity
327 | * @param color 状态栏颜色值
328 | * @return 状态栏矩形条
329 | */
330 | private static View createStatusBarView(Activity activity, int color) {
331 | // 绘制一个和状态栏一样高的矩形
332 | View statusBarView = new View(activity);
333 | LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
334 | getStatusBarHeight(activity));
335 | statusBarView.setLayoutParams(params);
336 | statusBarView.setBackgroundColor(color);
337 | return statusBarView;
338 | }
339 |
340 | /**
341 | * 生成一个和状态栏大小相同的半透明矩形条
342 | *
343 | * @param activity 需要设置的activity
344 | * @param color 状态栏颜色值
345 | * @param alpha 透明值
346 | * @return 状态栏矩形条
347 | */
348 | private static View createStatusBarView(Activity activity, int color, int alpha) {
349 | // 绘制一个和状态栏一样高的矩形
350 | View statusBarView = new View(activity);
351 | LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
352 | getStatusBarHeight(activity));
353 | statusBarView.setLayoutParams(params);
354 | statusBarView.setBackgroundColor(calculateStatusColor(color, alpha));
355 | return statusBarView;
356 | }
357 |
358 | /**
359 | * 设置根布局参数
360 | */
361 | private static void setRootView(Activity activity) {
362 | ViewGroup rootView = (ViewGroup) ((ViewGroup) activity.findViewById(android.R.id.content)).getChildAt(0);
363 | rootView.setFitsSystemWindows(true);
364 | rootView.setClipToPadding(true);
365 | }
366 |
367 | /**
368 | * 使状态栏透明
369 | */
370 | @TargetApi(Build.VERSION_CODES.KITKAT)
371 | private static void transparentStatusBar(Activity activity) {
372 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
373 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
374 | activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
375 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
376 | activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
377 | } else {
378 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
379 | }
380 | }
381 |
382 | /**
383 | * 创建半透明矩形 View
384 | *
385 | * @param alpha 透明值
386 | * @return 半透明 View
387 | */
388 | private static View createTranslucentStatusBarView(Activity activity, int alpha) {
389 | // 绘制一个和状态栏一样高的矩形
390 | View statusBarView = new View(activity);
391 | LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
392 | getStatusBarHeight(activity));
393 | statusBarView.setLayoutParams(params);
394 | statusBarView.setBackgroundColor(Color.argb(alpha, 0, 0, 0));
395 | return statusBarView;
396 | }
397 |
398 | /**
399 | * 获取状态栏高度
400 | *
401 | * @param context context
402 | * @return 状态栏高度
403 | */
404 | private static int getStatusBarHeight(Context context) {
405 | // 获得状态栏高度
406 | int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
407 | return context.getResources().getDimensionPixelSize(resourceId);
408 | }
409 |
410 | /**
411 | * 计算状态栏颜色
412 | *
413 | * @param color color值
414 | * @param alpha alpha值
415 | * @return 最终的状态栏颜色
416 | */
417 | private static int calculateStatusColor(int color, int alpha) {
418 | float a = 1 - alpha / 255f;
419 | int red = color >> 16 & 0xff;
420 | int green = color >> 8 & 0xff;
421 | int blue = color & 0xff;
422 | red = (int) (red * a + 0.5);
423 | green = (int) (green * a + 0.5);
424 | blue = (int) (blue * a + 0.5);
425 | return 0xff << 24 | red << 16 | green << 8 | blue;
426 | }
427 |
428 | public static void setImgTransparent(Activity activity){
429 | if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
430 | Window window = activity.getWindow();
431 | window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
432 | | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
433 | window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
434 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
435 | | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
436 | window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
437 | window.setStatusBarColor(Color.TRANSPARENT);
438 | window.setNavigationBarColor(Color.TRANSPARENT);
439 | }
440 | }
441 | }
442 |
--------------------------------------------------------------------------------
/gradationscroll/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | GradationScroll
3 |
4 |
--------------------------------------------------------------------------------
/gradationscroll/src/main/res/values/styleable.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/gradationscroll/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
10 |
14 |
--------------------------------------------------------------------------------
/gradationscroll/src/test/java/com/hankkin/gradationscroll/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.hankkin.gradationscroll;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hankkin/GradationTitleBar/edb820965d82a1db379d915f10bee996f11fda8f/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':gradationscroll'
2 |
--------------------------------------------------------------------------------