I do in onCreate :
viewPager =(ViewPager)getActivity().findViewById(R.id.main_content); This in onCreateView :
viewPager.setBackgroundResource(R.drawable.potehki_fon); Markup:
<?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/main_content" android:fitsSystemWindows="true" > <android.support.v4.view.ViewPager android:id="@+id/pager" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" /> <ImageView android:id="@+id/fab" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="end|bottom" android:layout_margin="10dp" android:src="@drawable/speaker_icon_on_shadow" /> </android.support.design.widget.CoordinatorLayout> When executing the code I see the following error:
java.lang.ClassCastException: android.support.design.widget.CoordinatorLayout cannot be cast to android.support.v4.view.ViewPager at com.example.potehki.potehki.PageFragment.onCreate(PageFragment.java:63)