0

I'm trying to add a bottom sheet to my layout, so I place all my fragment's layout inside a CoordinatorLayout:

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:tools="http://schemas.android.com/tools">

    <RelativeLayout
        android:id="@+id/myOriginalLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:animateLayoutChanges="true"
        android:clickable="true">

       ....
       ....

    </RelativeLayout>

    <FrameLayout
        android:id="@+id/bottom_sheet"
        android:layout_width="match_parent"
        android:layout_height="150dp"
        app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
    </FrameLayout>

</android.support.design.widget.CoordinatorLayout>

It keeps on crashing though when I try to inflate the layout, stating Error inflating class android.support.design.widget.CoordinatorLayout.

BVtp
  • 2,090
  • 2
  • 21
  • 50

2 Answers2

0

Use this theme by Changing from Activity with AppCompatActivity.

    <style name="Theme.DesignDemo" parent="Base.Theme.DesignDemo">
    </style>

    <style name="Base.Theme.DesignDemo" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">#673AB7</item>
        <item name="colorPrimaryDark">#512DA8</item>
        <item name="colorAccent">#FF4081</item>
        <item name="android:windowBackground">@color/window_background</item>
    </style>

Change your buildToolsVersion to 23.0.3. Then Sync your Gradle Again.

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId ""
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
}

And add this Dependencies.

dependencies {
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:design:23.4.0'
    compile 'com.android.support:cardview-v7:23.4.0'
}
Jay Rathod RJ
  • 10,321
  • 5
  • 27
  • 49
  • crashes unfortunately – BVtp May 24 '16 at 12:21
  • Can you tell me where and which crashed ? This settings working for me fine enough. – Jay Rathod RJ May 24 '16 at 12:24
  • yes, of course, the exception is : `java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.ActionBar.setDisplayOptions(int)' on a null object reference`. the line it crashes at is : `actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); ` – BVtp May 24 '16 at 12:25
  • I have a class of ActionBar handler so it causes problems – BVtp May 24 '16 at 12:26
  • For which purpose you have created. You should use `ToolBar` only with `AppCompatActivity`. – Jay Rathod RJ May 24 '16 at 12:27
  • @BVtp Make `AppCompatActivity` to `ActionBarActivity` and check. it will work. – Jay Rathod RJ May 24 '16 at 12:29
  • Yes it will not :). Because only work toolbar with `AppCompatActivity`. Check my answer here http://stackoverflow.com/questions/37353160/action-bar-not-shown-in-android-studio/37353507#37353507 – Jay Rathod RJ May 24 '16 at 12:36
  • so if I use a custom ActionBar I can't use AppCompatActivity? – BVtp May 24 '16 at 12:45
  • @BVtp Nope bro :). You must use `ToolBar` as per Material Design Concept. Appreciate my answer if it is useful to you. – Jay Rathod RJ May 24 '16 at 12:49
  • So basically the use of Activity instead of AppCompatActivity prevents me from using CoordinatorLayout? – BVtp May 24 '16 at 12:50
  • @BVtp Yes as Per New Material design concepts needful to use what i have all suggested thanks :). – Jay Rathod RJ May 24 '16 at 12:52
  • I'm a bit confused.. I need to erase the ActionBar I'm using entirely? and implement a whole new toolbar instead? Or did I misunderstand you? – BVtp May 24 '16 at 12:53
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/112793/discussion-between-jaydroider-and-bvtp). – Jay Rathod RJ May 24 '16 at 12:54
  • If you want to use `Coordinator Layout` and all that then you must need to change. ToolBar` will set dynamic Titles for you for each `Activity`. – Jay Rathod RJ May 24 '16 at 12:56
  • Sounds like a lot of work, converting from actionbar to toolbar.. :/ – BVtp May 24 '16 at 12:57
  • Changes bit will do the trick for you just follow my answer above which `Link` is provided in comment. and also lots of tutorial are their for dynamic `Tool Bar`. – Jay Rathod RJ May 24 '16 at 12:59
  • Thanks bro for appreciation up-vote it also so it will be helpful to others also thanks :). and let me know if you need any further help good luck :). – Jay Rathod RJ May 24 '16 at 13:06
  • hmmm. This shouldn't be the answer. It didn't solve the issue. – Shumin May 24 '16 at 17:30
  • https://guides.codepath.com/android/Extended-ActionBar-Guide - here AppCompatActivity is used with ActionBar. How does that work there and in my case it doesn't? – BVtp May 25 '16 at 14:33
  • I'm sorry, but you were wrong.. I was able to leave my ActionBar and use AppCompatActivity. All I had to do is change my AcrionBar to support.v7.ActionBar. – BVtp May 26 '16 at 08:36
0

The solution that solved the issue :

  1. The activity I was using was extending Activity, instead of AppCompatActivity, so that had to be changed.
  2. However, when changing Activity to AppCompatActivity I still had crashes because I was using the regular ActionBar. So the steps I had taken to fix that:

    a. call `getSupportActionBar()` instead of `getActionBar()`
    b. change `ActionBar` to `support.v7.app.ActionBar`
    
BVtp
  • 2,090
  • 2
  • 21
  • 50