我今天第一次尝试使用v7 21库。
我也在我的应用程序中使用FadingActionBar库。那个链接到图书馆 https://github.com/ManuelPeinado/FadingActionBar
在我使用appcompat v7 21库之前,应用程序一直运行良好。但现在我收到了这个错误。
Caused by: java.lang.NullPointerException
at com.manuelpeinado.fadingactionbar.FadingActionBarHelper.setActionBarBackgroundDrawable(FadingActionBarHelper.java:48)
at com.manuelpeinado.fadingactionbar.FadingActionBarHelperBase.initActionBar(FadingActionBarHelperBase.java:173)
at com.manuelpeinado.fadingactionbar.FadingActionBarHelper.initActionBar(FadingActionBarHelper.java:31)
at olkunmustafa.example.parallax.medyasef.com.parallaxanimationexample.MyActivity.onCreate(MyActivity.java:23)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
如果我将appcompat从v21更改为v20,一切都已修复。但我想使用v21。
这是我的值/ style.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:windowActionBarOverlay">true</item>
</style>
</resources>
MyActivity.java
public class MyActivity extends ActionBarActivity {
@Override
protected void onCreate( Bundle savedInstanceState ) {
super.onCreate( savedInstanceState );
FadingActionBarHelper helper = new FadingActionBarHelper()
.actionBarBackground( R.color.green_ms )
.headerLayout( R.layout.header )
.contentLayout( R.layout.activity_my );
setContentView( helper.createView( this ) );
helper.initActionBar( this );
}
}
的build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.0.1"
defaultConfig {
applicationId "olkunmustafa.example.parallax.medyasef.com.parallaxanimationexample"
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.+'
compile 'com.github.manuelpeinado.fadingactionbar:fadingactionbar:3.1.2'
}
抱歉英语不好。 谢谢你的帮助
答案 0 :(得分:6)
此库与新的AppCompat不兼容。其Github页面上已打开一个问题:Fading ActionBar Issues。开发人员知道这个问题,但与此同时,他发布了一个要点,说明如何使用新的Toolbar
小部件实现此效果:Toolbar fading effect
答案 1 :(得分:0)
奇怪的是,我正在使用fadingactionbar库,它适用于appcompat v7 21库。这是我的构建
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "23.0.0 rc3"
defaultConfig {
applicationId "com.test.aprido.testfadedactionbar"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.+'
compile 'com.github.manuelpeinado.fadingactionbar:fadingactionbar:3.1.2'
}
amd这是我的res / value / style.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="@android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">@style/Widget.ActionBar</item>
</style>
<style name="AppTheme.TranslucentActionBar">
<item name="android:actionBarStyle">@style/Widget.ActionBar.Transparent</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowContentOverlay">@null</item>
</style>
<style name="AppTheme.Light.TranslucentActionBar" parent="@android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">@style/Widget.Light.ActionBar.Transparent</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowContentOverlay">@null</item>
</style>
<style name="Widget" />
<style name="Widget.ActionBar" parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse" />
<style name="Widget.Light" />
<style name="Widget.Light.ActionBar" parent="@android:style/Widget.Holo.Light.ActionBar.Solid" />
<style name="Widget.ActionBar.Transparent">
<item name="android:background">@android:color/transparent</item>
</style>
<style name="Widget.Light.ActionBar.Transparent">
<item name="android:background">@android:color/transparent</item>
</style>
</resources>