├── sample ├── .gitignore ├── src │ └── main │ │ ├── res │ │ ├── drawable │ │ │ ├── pic1.jpg │ │ │ ├── pic2.jpg │ │ │ └── pic3.jpg │ │ ├── mipmap-xhdpi │ │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ │ └── ic_launcher.png │ │ ├── values │ │ │ ├── strings.xml │ │ │ ├── dimens.xml │ │ │ └── styles.xml │ │ ├── values-v19 │ │ │ └── styles.xml │ │ └── layout │ │ │ ├── demo2.xml │ │ │ ├── demo3.xml │ │ │ └── demo1.xml │ │ ├── java │ │ └── cn │ │ │ └── zhaiyifan │ │ │ └── interestingtitlebar │ │ │ └── demo │ │ │ ├── DemoActivity3.java │ │ │ ├── DemoActivity.java │ │ │ └── DemoActivity2.java │ │ └── AndroidManifest.xml ├── build.gradle └── proguard-rules.pro ├── interestingtitlebar ├── .gitignore ├── src │ └── main │ │ ├── res │ │ ├── values │ │ │ ├── strings.xml │ │ │ ├── styles.xml │ │ │ ├── colors.xml │ │ │ └── dimens.xml │ │ ├── values-v19 │ │ │ ├── dimens.xml │ │ │ └── styles.xml │ │ ├── drawable-xhdpi │ │ │ ├── status_bar_shadow.png │ │ │ ├── skin_nav_title_bar_bg.png │ │ │ ├── skin_nav_icon_l_return.9.png │ │ │ ├── skin_nav_icon_r_refresh.png │ │ │ ├── skin_nav_icon_l_return_click.9.png │ │ │ └── skin_nav_icon_r_refresh_click.png │ │ ├── drawable │ │ │ ├── selector_skin_nav_icon_l_return.xml │ │ │ └── selector_skin_nav_icon_r_refresh.xml │ │ ├── color │ │ │ └── selector_color_title.xml │ │ └── layout │ │ │ └── title_bar.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ └── cn │ │ └── zhaiyifan │ │ └── interestingtitlebar │ │ ├── ScrollAnimInterface.java │ │ ├── utils │ │ ├── CompatibilityUtil.java │ │ ├── ViewUtils.java │ │ └── PropertyUtils.java │ │ ├── ExtendRelativeLayout.java │ │ ├── ImmersiveTitleBar.java │ │ └── CustomTitleBar.java ├── build.gradle └── proguard-rules.pro ├── settings.gradle ├── art ├── Z1_1.jpg ├── Z1_2.jpg ├── Z1_3.jpg ├── Z1_4.jpg ├── MX4_1.jpg ├── MX4_2.jpg ├── MX4_3.jpg ├── MX4_4.jpg ├── recording.gif ├── xiaomi_1.jpg └── xiaomi_2.jpg ├── .gitignore ├── gradle.properties ├── README.md ├── gradlew.bat ├── gradlew └── LICENSE /sample/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /interestingtitlebar/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':sample', ':interestingtitlebar' 2 | -------------------------------------------------------------------------------- /art/Z1_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/markzhai/InterestingTitleBar/HEAD/art/Z1_1.jpg -------------------------------------------------------------------------------- /art/Z1_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/markzhai/InterestingTitleBar/HEAD/art/Z1_2.jpg -------------------------------------------------------------------------------- /art/Z1_3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/markzhai/InterestingTitleBar/HEAD/art/Z1_3.jpg -------------------------------------------------------------------------------- /art/Z1_4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/markzhai/InterestingTitleBar/HEAD/art/Z1_4.jpg -------------------------------------------------------------------------------- /art/MX4_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/markzhai/InterestingTitleBar/HEAD/art/MX4_1.jpg -------------------------------------------------------------------------------- /art/MX4_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/markzhai/InterestingTitleBar/HEAD/art/MX4_2.jpg -------------------------------------------------------------------------------- /art/MX4_3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/markzhai/InterestingTitleBar/HEAD/art/MX4_3.jpg -------------------------------------------------------------------------------- /art/MX4_4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/markzhai/InterestingTitleBar/HEAD/art/MX4_4.jpg -------------------------------------------------------------------------------- /art/recording.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/markzhai/InterestingTitleBar/HEAD/art/recording.gif -------------------------------------------------------------------------------- /art/xiaomi_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/markzhai/InterestingTitleBar/HEAD/art/xiaomi_1.jpg -------------------------------------------------------------------------------- /art/xiaomi_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/markzhai/InterestingTitleBar/HEAD/art/xiaomi_2.jpg -------------------------------------------------------------------------------- /sample/src/main/res/drawable/pic1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/markzhai/InterestingTitleBar/HEAD/sample/src/main/res/drawable/pic1.jpg -------------------------------------------------------------------------------- /sample/src/main/res/drawable/pic2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/markzhai/InterestingTitleBar/HEAD/sample/src/main/res/drawable/pic2.jpg -------------------------------------------------------------------------------- /sample/src/main/res/drawable/pic3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/markzhai/InterestingTitleBar/HEAD/sample/src/main/res/drawable/pic3.jpg -------------------------------------------------------------------------------- /interestingtitlebar/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | InterestingTitleBar 3 | 4 | -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/markzhai/InterestingTitleBar/HEAD/sample/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/markzhai/InterestingTitleBar/HEAD/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /interestingtitlebar/src/main/res/values-v19/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 68.5dp 4 | -------------------------------------------------------------------------------- /interestingtitlebar/src/main/res/drawable-xhdpi/status_bar_shadow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/markzhai/InterestingTitleBar/HEAD/interestingtitlebar/src/main/res/drawable-xhdpi/status_bar_shadow.png -------------------------------------------------------------------------------- /interestingtitlebar/src/main/res/drawable-xhdpi/skin_nav_title_bar_bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/markzhai/InterestingTitleBar/HEAD/interestingtitlebar/src/main/res/drawable-xhdpi/skin_nav_title_bar_bg.png -------------------------------------------------------------------------------- /interestingtitlebar/src/main/res/drawable-xhdpi/skin_nav_icon_l_return.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/markzhai/InterestingTitleBar/HEAD/interestingtitlebar/src/main/res/drawable-xhdpi/skin_nav_icon_l_return.9.png -------------------------------------------------------------------------------- /interestingtitlebar/src/main/res/drawable-xhdpi/skin_nav_icon_r_refresh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/markzhai/InterestingTitleBar/HEAD/interestingtitlebar/src/main/res/drawable-xhdpi/skin_nav_icon_r_refresh.png -------------------------------------------------------------------------------- /interestingtitlebar/src/main/res/drawable-xhdpi/skin_nav_icon_l_return_click.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/markzhai/InterestingTitleBar/HEAD/interestingtitlebar/src/main/res/drawable-xhdpi/skin_nav_icon_l_return_click.9.png -------------------------------------------------------------------------------- /interestingtitlebar/src/main/res/drawable-xhdpi/skin_nav_icon_r_refresh_click.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/markzhai/InterestingTitleBar/HEAD/interestingtitlebar/src/main/res/drawable-xhdpi/skin_nav_icon_r_refresh_click.png -------------------------------------------------------------------------------- /sample/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | InterestingTitleBarDemo 3 | 4 | Hello world! 5 | Settings 6 | 7 | -------------------------------------------------------------------------------- /sample/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /sample/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /interestingtitlebar/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /sample/src/main/res/values-v19/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | -------------------------------------------------------------------------------- /interestingtitlebar/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /interestingtitlebar/src/main/res/values-v19/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | -------------------------------------------------------------------------------- /interestingtitlebar/src/main/res/drawable/selector_skin_nav_icon_l_return.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /interestingtitlebar/src/main/res/drawable/selector_skin_nav_icon_r_refresh.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /interestingtitlebar/src/main/res/color/selector_color_title.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /interestingtitlebar/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #E0E0E0 4 | #FFFFFF 5 | #2D2D2D 6 | #802D2D2D 7 | #4D2D2D2D 8 | #000000 9 | #26000000 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | 15 | # Gradle files 16 | .gradle/ 17 | build/ 18 | /*/build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | 29 | gradle/ 30 | .idea/ 31 | .DS_Store 32 | /build 33 | /captures 34 | *.iml -------------------------------------------------------------------------------- /interestingtitlebar/src/main/java/cn/zhaiyifan/interestingtitlebar/ScrollAnimInterface.java: -------------------------------------------------------------------------------- 1 | package cn.zhaiyifan.interestingtitlebar; 2 | 3 | import android.widget.AbsListView; 4 | 5 | /** 6 | * Interface for scroll animation. 7 | *

8 | * Created by markzhai on 2015/3/8. 9 | */ 10 | public interface ScrollAnimInterface { 11 | /** 12 | * For ListView usage 13 | */ 14 | void onScroll(AbsListView view, int firstVisibleItem, int endFadeItem); 15 | 16 | /** 17 | * For ScrollView usage 18 | */ 19 | void onScroll(int y); 20 | } -------------------------------------------------------------------------------- /sample/src/main/res/layout/demo2.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | 14 | 17 | -------------------------------------------------------------------------------- /interestingtitlebar/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 22 5 | buildToolsVersion "22.0.1" 6 | 7 | defaultConfig { 8 | minSdkVersion 8 9 | targetSdkVersion 22 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 | } 24 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/demo3.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /interestingtitlebar/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17sp 5 | 20sp 6 | 50dp 7 | 43.5dp 8 | 11dp 9 | 155dp 10 | 10dp 11 | 36dp 12 | 60dp 13 | -------------------------------------------------------------------------------- /sample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 22 5 | buildToolsVersion "22.0.1" 6 | 7 | defaultConfig { 8 | applicationId "cn.zhaiyifan.interestingtitlebar.demo" 9 | minSdkVersion 8 10 | targetSdkVersion 22 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(dir: 'libs', include: ['*.jar']) 24 | compile project(':interestingtitlebar') 25 | } 26 | -------------------------------------------------------------------------------- /sample/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 D:\Android\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 | -------------------------------------------------------------------------------- /interestingtitlebar/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 D:\Android\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 | -------------------------------------------------------------------------------- /sample/src/main/java/cn/zhaiyifan/interestingtitlebar/demo/DemoActivity3.java: -------------------------------------------------------------------------------- 1 | package cn.zhaiyifan.interestingtitlebar.demo; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | import android.widget.TextView; 6 | 7 | import cn.zhaiyifan.interestingtitlebar.CustomTitleBar; 8 | 9 | /** 10 | * Demo for usage when set fitsSystemWindows="true" 11 | *

12 | * Created by markzhai on 2015/4/11. 13 | */ 14 | public class DemoActivity3 extends Activity { 15 | @Override 16 | public void onCreate(Bundle savedInstanceState) { 17 | super.onCreate(savedInstanceState); 18 | setContentView(R.layout.demo3); 19 | final CustomTitleBar bar = (CustomTitleBar) findViewById(R.id.title_bar); 20 | bar.setTitleTextView((TextView) bar.findViewById(R.id.bar_title)); 21 | bar.setTitle("DemoActivity3"); 22 | bar.setTitleBarFitsSystemWindows(true); 23 | } 24 | } -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 21 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/demo1.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 14 | 15 | 19 | 20 | 26 | 27 | 34 | 35 | 36 | 37 | 38 | 41 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # InterestingTitleBar [![GitHub release](https://img.shields.io/badge/sample%20apk-0.9.0-brightgreen.svg?style=flat)](https://github.com/markzhai/InterestingTitleBar/releases/download/v0.9.0/sample-debug.apk) 2 | Interesting android title bar with immersive status bar and scroll animation like tumblr app (color of icon and text on title bar gradually change to end color) 3 | 4 | ![Sample](art/recording.gif) 5 | 6 | Pre-requisites 7 | -------------- 8 | 9 | - Android SDK v8 10 | 11 | Immersive window modes 12 | ----------- 13 | 14 | Different from SystemBarTint project, this titlebar project doesn't require android:fitsSystemWindows="true", and it does all padding work for you. 15 | 16 | Usage 17 | ----- 18 | You may check the demo activity to see its usage, but nomally: 19 | 20 | ```java 21 | CustomTitleBar bar = (CustomTitleBar) findViewById(R.id.title_bar); 22 | bar.setTitleTextView((TextView)bar.findViewById(R.id.bar_title)); 23 | bar.setTransparentEnabled(true, 100, 600); 24 | bar.setTitle("DemoActivity"); 25 | bar.setTextShadowColor(getResources().getColor(R.color.bar_title_text_shadow)); 26 | bar.addViewToFadeList(findViewById(R.id.bar_left_button)); 27 | bar.addViewToFadeList(findViewById(R.id.bar_right_button)); 28 | bar.addViewToFadeList(findViewById(R.id.bar_title)); 29 | ``` 30 | 31 | What if fitsSystemWindows is true (should set clipToPadding to false) 32 | ```java 33 | bar.setTitleBarFitsSystemWindows(true); 34 | ``` 35 | The bar will do drawing of shadow on status bar for you. 36 | 37 | TODO 38 | ----------- 39 | 1. More animation. 40 | 2. Better support for immersive mode. 41 | 3. Material design support. 42 | 43 | Screenshots 44 | ----------- 45 | 46 | ![Transparent](art/Z1_1.jpg "Browse local music file") 47 | ![Turn to opaque](art/Z1_2.jpg "Fullscreen music player") 48 | ![Transparent listview](art/Z1_3.jpg "Fullscreen music player") 49 | ![Turn to opaque](art/Z1_4.jpg "Fullscreen music player") -------------------------------------------------------------------------------- /interestingtitlebar/src/main/java/cn/zhaiyifan/interestingtitlebar/utils/CompatibilityUtil.java: -------------------------------------------------------------------------------- 1 | package cn.zhaiyifan.interestingtitlebar.utils; 2 | 3 | import android.os.Build; 4 | 5 | import java.lang.reflect.Method; 6 | 7 | /** 8 | * Compatibility for special ROM 9 | *

10 | * Created by tigerliang on 2015/10/12. 11 | */ 12 | public class CompatibilityUtil { 13 | 14 | private static final String TAG = "CompatibilityUtil"; 15 | 16 | /** 17 | * Check whether is running Flyme 18 | * 19 | * @return 20 | */ 21 | public static boolean isFlyme() { 22 | try { 23 | // Invoke Build.hasSmartBar() 24 | final Method method = Build.class.getMethod("hasSmartBar"); 25 | return method != null; 26 | } catch (final Exception e) { 27 | return false; 28 | } 29 | } 30 | 31 | /** 32 | * Check whether is MIUI 33 | * 34 | * @return 35 | */ 36 | public static boolean isMIUI() { 37 | String miuiVer = PropertyUtils.getQuickly("ro.miui.ui.version.name", null); 38 | return miuiVer != null && miuiVer.contains("V"); 39 | } 40 | 41 | /** 42 | * Get MIUI version 43 | * 44 | * @return the MIUI version or -1 if failed to get this value. 45 | */ 46 | public static int getMIUIVersion() { 47 | int result = -1; 48 | String miuiVer = PropertyUtils.getQuickly("ro.miui.ui.version.name", null); 49 | if (miuiVer != null && miuiVer.contains("V")) { 50 | int versionStart = miuiVer.indexOf("V") + 1; 51 | if (versionStart < miuiVer.length()) { 52 | String version = miuiVer.substring(versionStart); 53 | try { 54 | result = Integer.parseInt(version); 55 | } catch (NumberFormatException e) { 56 | //omit 57 | } 58 | } 59 | } 60 | return result; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /interestingtitlebar/src/main/java/cn/zhaiyifan/interestingtitlebar/ExtendRelativeLayout.java: -------------------------------------------------------------------------------- 1 | package cn.zhaiyifan.interestingtitlebar; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.view.View; 6 | import android.widget.RelativeLayout; 7 | 8 | public class ExtendRelativeLayout extends RelativeLayout { 9 | 10 | private boolean mLayoutConsiderPadding = true; 11 | 12 | public ExtendRelativeLayout(Context context) { 13 | super(context); 14 | } 15 | 16 | public ExtendRelativeLayout(Context context, AttributeSet attrs) { 17 | super(context, attrs); 18 | } 19 | 20 | public ExtendRelativeLayout(Context context, AttributeSet attrs, int defStyle) { 21 | super(context, attrs, defStyle); 22 | } 23 | 24 | public void setLayoutConsiderPadding(boolean consider) { 25 | if (mLayoutConsiderPadding != consider) { 26 | mLayoutConsiderPadding = consider; 27 | requestLayout(); 28 | } 29 | } 30 | 31 | @Override 32 | protected void onLayout(boolean changed, int l, int t, int r, int b) { 33 | // The layout has actually already been performed and the positions cached. 34 | // Apply the cached values to the children. 35 | super.onLayout(changed, l, t, r, b); 36 | 37 | if (mLayoutConsiderPadding) { 38 | int count = getChildCount(); 39 | for (int i = 0; i < count; i++) { 40 | View child = getChildAt(i); 41 | if (child.getVisibility() == GONE) { 42 | continue; 43 | } 44 | 45 | int xOffset = 0; 46 | LayoutParams params = (LayoutParams) child.getLayoutParams(); 47 | final int[] rules = params.getRules(); 48 | if (rules[CENTER_IN_PARENT] != 0 || rules[CENTER_VERTICAL] != 0) { 49 | xOffset = (getPaddingTop() - getPaddingBottom()) / 2; 50 | } 51 | if (xOffset != 0) { 52 | child.offsetTopAndBottom(xOffset); 53 | } 54 | } 55 | } 56 | } 57 | } 58 | 59 | -------------------------------------------------------------------------------- /sample/src/main/java/cn/zhaiyifan/interestingtitlebar/demo/DemoActivity.java: -------------------------------------------------------------------------------- 1 | package cn.zhaiyifan.interestingtitlebar.demo; 2 | 3 | import android.app.Activity; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.view.View; 7 | import android.view.ViewTreeObserver; 8 | import android.widget.ScrollView; 9 | import android.widget.TextView; 10 | 11 | import cn.zhaiyifan.interestingtitlebar.CustomTitleBar; 12 | import cn.zhaiyifan.interestingtitlebar.utils.ViewUtils; 13 | 14 | public class DemoActivity extends Activity { 15 | @Override 16 | public void onCreate(Bundle savedInstanceState) { 17 | super.onCreate(savedInstanceState); 18 | ViewUtils.init(this); 19 | setContentView(R.layout.demo1); 20 | final CustomTitleBar bar = (CustomTitleBar) findViewById(R.id.title_bar); 21 | bar.setTitleTextView((TextView)bar.findViewById(R.id.bar_title)); 22 | bar.setTransparentEnabled(true, 100, 600); 23 | bar.setTitle("DemoActivity"); 24 | bar.setTextShadowColor(getResources().getColor(R.color.bar_title_text_shadow)); 25 | bar.addViewToFadeList(findViewById(R.id.bar_left_button)); 26 | bar.addViewToFadeList(findViewById(R.id.bar_right_button)); 27 | bar.addViewToFadeList(findViewById(R.id.bar_title)); 28 | 29 | final ScrollView scrollView = (ScrollView) findViewById(R.id.scrollView); 30 | scrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() { 31 | 32 | @Override 33 | public void onScrollChanged() { 34 | bar.onScroll(scrollView.getScrollY()); 35 | } 36 | }); 37 | scrollView.findViewById(R.id.c1).setOnClickListener(new View.OnClickListener() { 38 | @Override 39 | public void onClick(View v) { 40 | startActivity(new Intent(DemoActivity.this, DemoActivity2.class)); 41 | } 42 | }); 43 | scrollView.findViewById(R.id.c2).setOnClickListener(new View.OnClickListener() { 44 | @Override 45 | public void onClick(View v) { 46 | startActivity(new Intent(DemoActivity.this, DemoActivity3.class)); 47 | } 48 | }); 49 | } 50 | } -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /interestingtitlebar/src/main/java/cn/zhaiyifan/interestingtitlebar/utils/ViewUtils.java: -------------------------------------------------------------------------------- 1 | package cn.zhaiyifan.interestingtitlebar.utils; 2 | 3 | import android.content.Context; 4 | import android.content.res.Resources; 5 | import android.os.Build; 6 | import android.util.DisplayMetrics; 7 | import android.view.View; 8 | import android.view.animation.AlphaAnimation; 9 | 10 | /** 11 | * Created by markzhai on 2015/1/14. 12 | */ 13 | public class ViewUtils { 14 | 15 | static private float density = -1; 16 | static private int screenWidth = -1; 17 | static private int screenHeight = -1; 18 | 19 | public static void init(Context context) { 20 | if (density == -1) { 21 | DisplayMetrics metrics = context.getResources().getDisplayMetrics(); 22 | density = metrics.density; 23 | if (metrics.widthPixels < metrics.heightPixels) { 24 | screenWidth = metrics.widthPixels; 25 | screenHeight = metrics.heightPixels; 26 | } else { // 部分机器使用application的context宽高反转 27 | screenHeight = metrics.widthPixels; 28 | screenWidth = metrics.heightPixels; 29 | } 30 | } 31 | } 32 | 33 | public static int getStatusBarHeight(Context context) { 34 | int result = 0; 35 | Resources resources = context.getResources(); 36 | int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android"); 37 | if (resourceId > 0) { 38 | result = resources.getDimensionPixelSize(resourceId); 39 | } 40 | if (result <= 0) { 41 | result = dpToPx(25); 42 | } 43 | return result; 44 | } 45 | 46 | public static float getDensity() { 47 | return density; 48 | } 49 | 50 | public static int getScreenWidth() { 51 | return screenWidth; 52 | } 53 | 54 | public static int getScreenHeight() { 55 | return screenHeight; 56 | } 57 | 58 | public static int dpToPx(float dp) { 59 | return Math.round(dp * getDensity()); 60 | } 61 | 62 | public static int PxToDp(float px) { 63 | return Math.round(px / getDensity()); 64 | } 65 | 66 | /** 67 | * 在xml里设置android:alpha对api11以前的系统不起作用,所以在代码里获取并设置透明度 68 | */ 69 | public static void setAlpha(View view, float alphaValue) { 70 | if (view == null) { 71 | return; 72 | } 73 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { 74 | view.setAlpha(alphaValue); 75 | } else { 76 | AlphaAnimation alpha = new AlphaAnimation(alphaValue, alphaValue); 77 | alpha.setDuration(0); 78 | alpha.setFillAfter(true); 79 | view.startAnimation(alpha); 80 | } 81 | } 82 | } -------------------------------------------------------------------------------- /sample/src/main/java/cn/zhaiyifan/interestingtitlebar/demo/DemoActivity2.java: -------------------------------------------------------------------------------- 1 | package cn.zhaiyifan.interestingtitlebar.demo; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.AbsListView; 8 | import android.widget.BaseAdapter; 9 | import android.widget.ImageView; 10 | import android.widget.ListView; 11 | import android.widget.TextView; 12 | 13 | import cn.zhaiyifan.interestingtitlebar.CustomTitleBar; 14 | 15 | /** 16 | * Created by markzhai on 2015/1/14. 17 | */ 18 | public class DemoActivity2 extends Activity { 19 | @Override 20 | public void onCreate(Bundle savedInstanceState) { 21 | super.onCreate(savedInstanceState); 22 | setContentView(R.layout.demo2); 23 | final CustomTitleBar bar = (CustomTitleBar) findViewById(R.id.title_bar); 24 | bar.setTitleTextView((TextView)bar.findViewById(R.id.bar_title)); 25 | bar.setTransparentEnabled(true, 50, 500); 26 | bar.setTitle("DemoActivity2"); 27 | bar.addViewToFadeList(findViewById(R.id.bar_left_button)); 28 | bar.addViewToFadeList(findViewById(R.id.bar_right_button)); 29 | bar.addViewToFadeList(findViewById(R.id.bar_title)); 30 | ListView listView = (ListView)findViewById(R.id.list_view); 31 | listView.setAdapter(new BaseAdapter() { 32 | @Override 33 | public int getCount() { 34 | return 20; 35 | } 36 | 37 | @Override 38 | public Object getItem(int position) { 39 | return null; 40 | } 41 | 42 | @Override 43 | public long getItemId(int position) { 44 | return position; 45 | } 46 | 47 | @Override 48 | public View getView(int position, View convertView, ViewGroup parent) { 49 | if (position == 0) { 50 | ImageView imageView = new ImageView(DemoActivity2.this); 51 | imageView.setImageResource(R.drawable.pic3); 52 | imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); 53 | return imageView; 54 | } 55 | TextView textView = new TextView(DemoActivity2.this); 56 | textView.setMinimumHeight(100); 57 | textView.setTextSize(18); 58 | textView.setText("row: " + position); 59 | return textView; 60 | } 61 | }); 62 | listView.setOnScrollListener(new AbsListView.OnScrollListener() { 63 | @Override 64 | public void onScrollStateChanged(AbsListView view, int scrollState) { 65 | 66 | } 67 | 68 | @Override 69 | public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { 70 | bar.onScroll(view, firstVisibleItem, 0); 71 | } 72 | }); 73 | } 74 | } -------------------------------------------------------------------------------- /interestingtitlebar/src/main/res/layout/title_bar.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 12 | 26 | 27 | 28 | 34 | 35 | 36 |