Hi, I am trying to implement a simple Android Bottom sheet, and my used xml is the following:
MY XML
<?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/main_content" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="Effects" android:id="@+id/effects" android:textStyle="italic"/> <!--contains my layout for buttons, nested layout etc etc--> </LinearLayout <android.support.v4.widget.NestedScrollView android:id="@+id/color_effects_bottom_sheet" android:layout_width="match_parent" android:layout_height="350dp" android:clipToPadding="true" app:behavior_hideable="true" android:background="@android:color/holo_orange_light" app:layout_behavior="android.support.design.widget.BottomSheetBehavior"> <TextView android:layout_width="match_parent" android:layout_height="match_parent" android:text="Please Set the Color Effects here!" android:padding="16dp" android:textSize="16sp"/> </android.support.v4.widget.NestedScrollView>
The code behind this XML is as follows:
Code for
public class MainActivity extends the action {
//Variables for bottom sheets calls private Button btn_effects; private BottomSheetBehavior mBottomSheetBehavior; private CoordinatorLayout coordinatorLayout; //////////////////////////////////// @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //locate coordinator layout coordinatorLayout=(CoordinatorLayout)findViewById(R.id.main_content); //locate bottom sheet View color_bottomSheet = coordinatorLayout.findViewById( R.id.color_effects_bottom_sheet); //View scene_bottomSheet = coordinatorLayout.findViewById( R.id.scenes_bottom_sheet); //effects button btn_effects=(Button)findViewById(R.id.effects); //scenes button btn_scenes=(Button)findViewById(R.id.scenes); //settings button btn_settings=(Button)findViewById(R.id.settings); //bottom sheet behavior mBottomSheetBehavior = BottomSheetBehavior.from(color_bottomSheet); //effects button listener btn_effects.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED); } }); }
}
Problem
The problem is that when I try to run this code, it resets my application and throws this exception all the time.
An exception
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.bottomsheetexample, PID: 22875 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.bottomsheetexample/com.example.bottomsheetexample.MainActivity}: android.view.InflateException: Binary XML file line
Need
I am mainly trying to implement bottom sheets for the first time. I want to add a few bottom sheets to find out how to use them in an application.
My activity is full-screen activity with the following application theme
android:theme="@android:style/Theme.DeviceDefault.NoActionBar.Fullscreen">
I want to use full-screen activity and I want to implement several bottom sheets on the buttons for listening to the buttons!
source share