Rukey7 / IjkPlayerView

An media player for Android
http://blog.csdn.net/github_35180164/article/details/53376923
470 stars 119 forks source link

Caused by: java.lang.IllegalArgumentException: Context must be AppCompatActivity 为什么不能使用Toolbar #45

Closed TigerSkinZhang closed 5 years ago

TigerSkinZhang commented 5 years ago

<android.support.design.widget.CoordinatorLayout android:id="@+id/tg" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/background_light" android:fitsSystemWindows="true" android:layout_above="@+id/bottom"

        <android.support.design.widget.AppBarLayout
            android:id="@+id/app_bar"
            android:layout_width="match_parent"
            android:layout_height="300dp"
            android:background="@color/app_background_color"
            android:fitsSystemWindows="true"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/toolbar_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:fitsSystemWindows="true"
                app:contentScrim="#1fcfb6"
                app:expandedTitleMarginEnd="64dp"

                app:expandedTitleMarginStart="48dp"
                app:layout_scrollFlags="scroll|exitUntilCollapsed">
                <com.dl7.player.media.IjkPlayerView
                    android:id="@+id/player_view"
                    android:layout_width="match_parent"
                    android:layout_height="250dp"/>

                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?android:attr/actionBarSize"
                    app:layout_collapseMode="pin"
                    android:background="@color/transparent"
                  />

            </android.support.design.widget.CollapsingToolbarLayout>
TigerSkinZhang commented 5 years ago

作者,您好,我的activity也是继承了AppCompatActivity ,但是使用了toobar,出现上述错误,有没有什么办法解决

TigerSkinZhang commented 5 years ago

改了您的源码,自己解决了 使用此方法获取activity private static Activity scanForActivity(Context cont) { if (cont == null) return null; else if (cont instanceof Activity) return (Activity) cont; else if (cont instanceof ContextWrapper) return scanForActivity(((ContextWrapper) cont).getBaseContext());

    return null;
}
Rukey7 commented 5 years ago

记得当初是为了处理全屏加的判断,你源码自己调最好