我想在我的应用程序中使用snackbar,所以我为此设置了下面的代码
public class FragmentAddProperty extends Fragment
{
RelativeLayout mRelative
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
view = inflater.inflate(R.layout.layout_1,
container, false);
mRelative = (RelativeLayout) view.findViewById(R.id.edt_pro_city);
Snackbar.make(mRelative, "No images.", Snackbar.LENGTH_LONG).show();
}
}
编辑
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/edt_pro_city"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f8f8f8"
android:orientation="vertical" >
<ImageView
android:id="@+id/sample_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:src="@drawable/icon_list"
android:visibility="visible" />
</RelativeLayout>
结果我得到了以下错误
java.lang.ClassCastException: android.widget.RelativeLayout cannot be cast to android.support.design.widget.Snackbar$SnackbarLayout
我该如何解决这个问题?
所有建议都是可观的