kmshack / Android-ParallaxHeaderViewPager

DEPRECATED
Apache License 2.0
1.39k stars 336 forks source link

AppCompat v21 support? #9

Open nitrico opened 9 years ago

nitrico commented 9 years ago

Is there any way to get it working with the new appcompat support library? They introduced many changes on it and I don't find how to solve the problem of getActionBarIconView() always returning null.

nitrico commented 9 years ago

Ok, I managed it by adding a toolbar to the activity layout and setting it as the ActionBar. This toolbar contains an ImageView and a TextView to replace the former ActionBar's icon and title.

gfucka commented 9 years ago

Hi, please can you explain me how you solve it?? I have to add a toolbar in activity_main.xml and then?? How i set it as ActionBar??

Thank you so much

nitrico commented 9 years ago

Sure :) That's what I did:

In TransparentTheme style:

Add this toolbar at the end of the activity_main.xml but inside the main root FrameLayout. Of course you can tweak it:

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="56dp" >
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal" >
        <ImageView
            android:id="@+id/icon"
            android:layout_marginLeft="12dp"
            android:layout_marginTop="6dp"
            android:layout_marginBottom="6dp"
            android:layout_width="44dp"
            android:layout_height="44dp" />
        <TextView
            android:id="@+id/title"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:gravity="center_vertical"
            style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title" />
    </LinearLayout>
</android.support.v7.widget.Toolbar>

Then, in the MainActivity.java:

And I think that's all.

gfucka commented 9 years ago

Hi, I do all but now I have NullPointerException on line 156 of MainActivity float scaleY = 1.0F + interpolation * (mRect2.height() / mRect1.height() - 1.0F);

why??

Thanks again

nitrico commented 9 years ago

Hmm... don't know why. I have made all the modifications again, thinking I could forget anything but it just works fine for me. You can post the trace of the exception to try to find the problem.

jigar-sp commented 9 years ago

thanks...

its perfectly working

ed-george commented 9 years ago

Thank you @nitrico, I can also confirm that this work around does rectify the issues with AppCompat v21

cjgehinscott commented 9 years ago

I can confirm that this fix does not work anymore...

07-07 09:56:15.633 3430-3430/com.bah.is.esd.zoneapp E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.bah.is.esd.zoneapp, PID: 3430 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.bah.is.esd.zoneapp/com.bah.is.esd.zoneapp.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setAlpha(float)' on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) at android.app.ActivityThread.access$800(ActivityThread.java:151) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5254) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setAlpha(float)' on a null object reference at com.bah.is.esd.nineoldandroids.view.ViewHelper$Honeycomb.setAlpha(ViewHelper.java:185) at com.bah.is.esd.nineoldandroids.view.ViewHelper.setAlpha(ViewHelper.java:19) at com.bah.is.esd.zoneapp.MainActivity.layoutView(MainActivity.java:525) at com.bah.is.esd.zoneapp.MainActivity.onCreate(MainActivity.java:135) at android.app.Activity.performCreate(Activity.java:5990) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)             at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)             at android.app.ActivityThread.access$800(ActivityThread.java:151)             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)             at android.os.Handler.dispatchMessage(Handler.java:102)             at android.os.Looper.loop(Looper.java:135)             at android.app.ActivityThread.main(ActivityThread.java:5254)             at java.lang.reflect.Method.invoke(Native Method)             at java.lang.reflect.Method.invoke(Method.java:372)             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

cjgehinscott commented 9 years ago

Make your theme a child of Theme.AppCompat.Light.NoActionBar like so: screen shot 2015-07-07 at 11 23 32 am