-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/workspace.xml | ||
/.idea/libraries | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 25 | ||
buildToolsVersion "25.0.2" | ||
defaultConfig { | ||
applicationId "com.xu.kevin.toolbaralphabehavior" | ||
minSdkVersion 16 | ||
targetSdkVersion 25 | ||
versionCode 1 | ||
versionName "1.0" | ||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
compile fileTree(dir: 'libs', include: ['*.jar']) | ||
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { | ||
exclude group: 'com.android.support', module: 'support-annotations' | ||
}) | ||
compile 'com.android.support:appcompat-v7:25.1.1' | ||
testCompile 'junit:junit:4.12' | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in C:\Users\kevin\AppData\Local\Android\sdk/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the proguardFiles | ||
# directive in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.xu.kevin.toolbaralphabehavior; | ||
|
||
import android.content.Context; | ||
import android.support.test.InstrumentationRegistry; | ||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Instrumentation test, which will execute on an Android device. | ||
* | ||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class ExampleInstrumentedTest { | ||
@Test | ||
public void useAppContext() throws Exception { | ||
// Context of the app under test. | ||
Context appContext = InstrumentationRegistry.getTargetContext(); | ||
|
||
assertEquals("com.xu.kevin.toolbaralphabehavior", appContext.getPackageName()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.xu.kevin.toolbaralphabehavior"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<activity android:name=".MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.xu.kevin.toolbaralphabehavior; | ||
|
||
import android.content.Context; | ||
import android.support.v4.widget.NestedScrollView; | ||
import android.util.AttributeSet; | ||
|
||
|
||
/** | ||
* 如果 | ||
*/ | ||
public class CustomNestedScrollView extends NestedScrollView { | ||
public ScrollInterface scrollInterface; | ||
|
||
public CustomNestedScrollView(Context context) { | ||
this(context, null); | ||
} | ||
|
||
public CustomNestedScrollView(Context context, AttributeSet attrs) { | ||
this(context, attrs, 0); | ||
} | ||
|
||
public CustomNestedScrollView(Context context, AttributeSet attrs, int defStyleAttr) { | ||
super(context, attrs, defStyleAttr); | ||
} | ||
|
||
|
||
@Override | ||
protected void onScrollChanged(int l, int t, int oldl, int oldt) { | ||
super.onScrollChanged(l, t, oldl, oldt); | ||
if(scrollInterface!=null){ | ||
scrollInterface.onSChanged(l, t, oldl, oldt); | ||
} | ||
} | ||
|
||
|
||
public void setOnCustomScroolChangeListener(ScrollInterface t) { | ||
this.scrollInterface = t; | ||
} | ||
|
||
/** | ||
* 定义滑动接口 | ||
* @param | ||
*/ | ||
public interface ScrollInterface { | ||
public void onSChanged(int l, int t, int oldl, int oldt); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.xu.kevin.toolbaralphabehavior; | ||
|
||
import android.app.Activity; | ||
import android.content.Context; | ||
import android.os.Build; | ||
import android.os.Bundle; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.support.v7.widget.Toolbar; | ||
import android.view.Window; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
private ToolBarAlphaBehavior toolBarAlphaBehavior; | ||
private Toolbar toolbar; | ||
private CustomNestedScrollView mScrollView; | ||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
mScrollView=(CustomNestedScrollView)findViewById(R.id.scrollView); | ||
initToolBar(); | ||
} | ||
|
||
private void initToolBar(){ | ||
toolbar=(Toolbar)findViewById(R.id.toolbar); | ||
toolbar.setNavigationIcon(R.drawable.draw_back); | ||
setSupportActionBar(toolbar); | ||
toolbar.setTitle(""); | ||
getSupportActionBar().setDisplayShowTitleEnabled(false); | ||
|
||
int imageViewHeight=dip2px(360); | ||
//toolBar变色回调 | ||
toolBarAlphaBehavior = new ToolBarAlphaBehavior(getBaseContext(),toolbar, "000000", new ToolBarAlphaBehavior.CallBack() { | ||
@Override | ||
public void callBack(int color) { | ||
setStatuBarColor(color); | ||
} | ||
},imageViewHeight); | ||
|
||
//初始化toolBar 颜色 | ||
toolBarAlphaBehavior.setAlPha(ToolBarAlphaBehavior.minAlpha);//toolbar透明度初始化 | ||
|
||
//监听 NestScrollView | ||
mScrollView.setOnCustomScroolChangeListener(new CustomNestedScrollView.ScrollInterface() { | ||
@Override | ||
public void onSChanged(int l, int t, int oldl, int oldt) { | ||
//渐变色. | ||
if (toolBarAlphaBehavior != null) | ||
toolBarAlphaBehavior.onNestedScroll(t); | ||
} | ||
}); | ||
} | ||
|
||
public void setStatuBarColor( int color) { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | ||
Window window = this.getWindow(); | ||
window.setStatusBarColor(color); | ||
} | ||
} | ||
|
||
public int dip2px( float dpValue) { | ||
final float scale =this.getResources().getDisplayMetrics().density; | ||
return (int) (dpValue * scale + 0.5f); | ||
} | ||
} |