{"id":144,"date":"2020-09-30T00:52:09","date_gmt":"2020-09-30T00:52:09","guid":{"rendered":"https:\/\/barahasoft.com.np\/blog\/?p=144"},"modified":"2020-09-30T01:57:08","modified_gmt":"2020-09-30T01:57:08","slug":"android-bottom-sheet-customization","status":"publish","type":"post","link":"https:\/\/barahasoft.com.np\/blog\/android-bottom-sheet-customization\/","title":{"rendered":"Android Bottom Sheet Customization"},"content":{"rendered":"\n<p>Bottom Sheet is a CoordinatorLayout&#8217;s child view that slides up from bottom. It is material component and frequently used in android. Basically there are two types of Bottom Sheet , viz : <strong><em>Persistent Bottom Sheet(Standard)<\/em><\/strong> and <strong><em>Modal Bottom Sheet<\/em><\/strong>.  As name suggests , in former one we can have interaction with other remaining area in screen and later one behaves like modal where we can&#8217;t interact with remaining area also the are is dimmed.<\/p>\n\n\n\n<p>Now let&#8217;s go with the title of this post, here we deal with customizing Persistent Bottom Sheet where we add rounded, stroked background.<\/p>\n\n\n\n<p><strong>Step1:<\/strong> create layout file for bottom sheet named <strong><em>bottom_sheet_standard.xml<\/em><\/strong><\/p>\n\n\n\n<p>Here i have used Constraintlayout as root , we can also use LinearLayout but i suggest you to use ConstraintLayout for better performance. NB: this layout is normal ConstraintLayout with layout_behaviour <em>com.google.android.material.bottomsheet.BottomSheetBehavior<\/em> which force to work as Bottom Sheet.<\/p>\n\n\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;\n&lt;androidx.constraintlayout.widget.ConstraintLayout xmlns:android=&quot;http:\/\/schemas.android.com\/apk\/res\/android&quot;\n    xmlns:app=&quot;http:\/\/schemas.android.com\/apk\/res-auto&quot;\n    android:layout_width=&quot;match_parent&quot;\n    android:layout_height=&quot;wrap_content&quot;\n    android:background=&quot;@drawable\/bg_bs&quot;\n    android:id=&quot;@+id\/bottomSheet&quot;\n    app:behavior_hideable=&quot;true&quot;\n    android:clickable=&quot;true&quot;\n    app:behavior_peekHeight=&quot;1dp&quot;\n    android:paddingBottom=&quot;15dp&quot;\n    app:layout_behavior=&quot;com.google.android.material.bottomsheet.BottomSheetBehavior&quot;&gt;\n\n    &lt;androidx.constraintlayout.widget.Guideline\n        android:id=&quot;@+id\/gll&quot;\n        android:orientation=&quot;vertical&quot;\n        app:layout_constraintGuide_begin=&quot;10dp&quot;\n        android:layout_width=&quot;wrap_content&quot;\n        android:layout_height=&quot;wrap_content&quot; \/&gt;\n\n    &lt;androidx.constraintlayout.widget.Guideline\n        android:id=&quot;@+id\/glr&quot;\n        android:orientation=&quot;vertical&quot;\n        app:layout_constraintGuide_end=&quot;10dp&quot;\n        android:layout_width=&quot;wrap_content&quot;\n        android:layout_height=&quot;wrap_content&quot; \/&gt;\n    &lt;TextView\n        android:id=&quot;@+id\/tvTitle&quot;\n        android:text=&quot;@string\/message_login_first&quot;\n        android:drawableLeft=&quot;@drawable\/ic_info&quot;\n        android:textStyle=&quot;bold&quot;\n        android:textColor=&quot;@color\/black&quot;\n        android:layout_marginTop=&quot;20dp&quot;\n        android:layout_width=&quot;wrap_content&quot;\n        android:layout_height=&quot;wrap_content&quot;\n        app:layout_constraintTop_toTopOf=&quot;parent&quot;\n        app:layout_constraintStart_toStartOf=&quot;@id\/gll&quot;\n        app:layout_constraintEnd_toEndOf=&quot;@id\/glr&quot;\n        \/&gt;\n\n    &lt;ImageView\n        android:id=&quot;@+id\/ivLogin&quot;\n        android:layout_width=&quot;35dp&quot;\n        android:layout_height=&quot;35dp&quot;\n        android:layout_marginStart=&quot;16dp&quot;\n        android:layout_marginTop=&quot;16dp&quot;\n        app:layout_constraintStart_toStartOf=&quot;@id\/gll&quot;\n        app:layout_constraintTop_toBottomOf=&quot;@id\/tvTitle&quot;\n        android:src=&quot;@drawable\/ic_logout&quot; \/&gt;\n\n    &lt;TextView\n        android:id=&quot;@+id\/tvLogin&quot;\n        android:layout_width=&quot;wrap_content&quot;\n        android:layout_height=&quot;wrap_content&quot;\n        android:layout_marginStart=&quot;8dp&quot;\n        android:text=&quot;Login&quot;\n        android:onClick=&quot;openLoginPage&quot;\n        android:textColor=&quot;#292929&quot;\n        android:textSize=&quot;16sp&quot;\n        app:layout_constraintBottom_toBottomOf=&quot;@+id\/ivLogin&quot;\n        app:layout_constraintStart_toEndOf=&quot;@+id\/ivLogin&quot;\n        app:layout_constraintTop_toTopOf=&quot;@+id\/ivLogin&quot; \/&gt;\n\n    &lt;ImageView\n        android:id=&quot;@+id\/ivClose&quot;\n        android:layout_width=&quot;35dp&quot;\n        android:layout_height=&quot;35dp&quot;\n        android:layout_marginStart=&quot;16dp&quot;\n        android:layout_marginTop=&quot;16dp&quot;\n        app:layout_constraintStart_toStartOf=&quot;@id\/gll&quot;\n        app:layout_constraintTop_toBottomOf=&quot;@id\/ivLogin&quot;\n        android:src=&quot;@android:drawable\/ic_menu_close_clear_cancel&quot; \/&gt;\n\n    &lt;TextView\n        android:id=&quot;@+id\/tvCancel&quot;\n        android:layout_width=&quot;wrap_content&quot;\n        android:layout_height=&quot;wrap_content&quot;\n        android:layout_marginStart=&quot;8dp&quot;\n        android:text=&quot;Close&quot;\n        android:onClick=&quot;closeSheet&quot;\n        android:textColor=&quot;#292929&quot;\n        android:textSize=&quot;16sp&quot;\n        app:layout_constraintBottom_toBottomOf=&quot;@+id\/ivClose&quot;\n        app:layout_constraintStart_toEndOf=&quot;@+id\/ivClose&quot;\n        app:layout_constraintTop_toTopOf=&quot;@+id\/ivClose&quot; \/&gt;\n&lt;\/androidx.constraintlayout.widget.ConstraintLayout&gt;\n\n<\/pre>\n\n\n<p>Attribute <em>app:behavior_hideable<\/em> specify if it is hideable when swiped down, android:clickable= true makes sure that view under Bottom Sheet which is hiddend due to overlap  is not clickable. <\/p>\n\n\n\n<p>In editor above layout like <\/p>\n\n\n\n<p><img loading=\"lazy\" width=\"410\" height=\"289\" class=\"wp-image-146\" style=\"width: 150px;\" src=\"https:\/\/barahasoft.com.np\/blog\/wp-content\/uploads\/2020\/09\/bottom_sheet_standard.png\" alt=\"\" srcset=\"https:\/\/barahasoft.com.np\/blog\/wp-content\/uploads\/2020\/09\/bottom_sheet_standard.png 410w, https:\/\/barahasoft.com.np\/blog\/wp-content\/uploads\/2020\/09\/bottom_sheet_standard-300x211.png 300w\" sizes=\"(max-width: 410px) 100vw, 410px\" \/><\/p>\n\n\n\n<p><strong>Step2:<\/strong> including above file inside main layout (CoordinateLayout) where bottom sheet is to be shown.<\/p>\n\n\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;\n&lt;androidx.coordinatorlayout.widget.CoordinatorLayout\n    xmlns:android=&quot;http:\/\/schemas.android.com\/apk\/res\/android&quot;\n    xmlns:app=&quot;http:\/\/schemas.android.com\/apk\/res-auto&quot;\n    xmlns:tools=&quot;http:\/\/schemas.android.com\/tools&quot;\n    android:layout_width=&quot;match_parent&quot;\n    android:layout_height=&quot;match_parent&quot;\n    android:focusable=&quot;true&quot;\n    android:focusableInTouchMode=&quot;true&quot;&gt;\n\n    ...\n    &lt;include\n        android:id=&quot;@+id\/bottomNavigation&quot;\n        layout=&quot;@layout\/bottom_navigation&quot;\n        android:layout_width=&quot;match_parent&quot;\n        android:layout_height=&quot;match_parent&quot; \/&gt;\n    &lt;include layout=&quot;@layout\/bottom_sheet_standard&quot; \/&gt;\n&lt;\/androidx.coordinatorlayout.widget.CoordinatorLayout&gt;\n<\/pre>\n\n\n<p><strong>Step3:<\/strong> initialization of Bottom Sheet and click event to show \/ hide inside <strong><em>MainActivity.kt<\/em><\/strong><\/p>\n\n\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n\/\/inside onCreate\nbottomSheetBehavior = BottomSheetBehavior.from(bottomSheet)\n\nbottomSheetBehavior.addBottomSheetCallback(object :\nBottomSheetBehavior.BottomSheetCallback() {\n            override fun onSlide(bottomSheet: View, slideOffset: Float) {\n            }\n\n            override fun onStateChanged(bottomSheet: View, newState: Int) {\n               \n            }\n        })\n\nbinding!!.mButton.setOnClickListener {\nval state =\n                    if (bottomSheetBehavior.state == BottomSheetBehavior.STATE_EXPANDED)\n                        BottomSheetBehavior.STATE_COLLAPSED\n                    else\n                        BottomSheetBehavior.STATE_EXPANDED\n            bottomSheetBehavior.state = state\n\n           \n        }\n\n\n<\/pre>\n\n\n<p><strong>Results:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"512\" height=\"512\" src=\"https:\/\/barahasoft.com.np\/blog\/wp-content\/uploads\/2020\/09\/customized_bottom_sheet.gif\" alt=\"\" class=\"wp-image-158\"\/><\/figure>\n\n\n\n<p>Other References:<\/p>\n\n\n\n<p><a href=\"https:\/\/developer.android.com\/reference\/com\/google\/android\/material\/bottomsheet\/package-summary\">https:\/\/developer.android.com\/reference\/com\/google\/android\/material\/bottomsheet\/package-summary<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/material.io\/develop\/android\/components\/sheets-bottom\">https:\/\/material.io\/develop\/android\/components\/sheets-bottom<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Bottom Sheet is a CoordinatorLayout&#8217;s child view that slides up from bottom. It is material component and frequently used in android. Basically there are two types of Bottom Sheet , viz : Persistent Bottom Sheet(Standard) and Modal Bottom Sheet. As name suggests , in former one we can have interaction with other remaining area in [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":151,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4],"tags":"BarahaSoft,Bottom Sheet,Persistent Bottom Sheet,Android Bottom Sheet,Android Material Component","yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v15.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Android Bottom Sheet Customization - BS Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/barahasoft.com.np\/blog\/android-bottom-sheet-customization\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Android Bottom Sheet Customization - BS Blog\" \/>\n<meta property=\"og:description\" content=\"Bottom Sheet is a CoordinatorLayout&#8217;s child view that slides up from bottom. It is material component and frequently used in android. Basically there are two types of Bottom Sheet , viz : Persistent Bottom Sheet(Standard) and Modal Bottom Sheet. As name suggests , in former one we can have interaction with other remaining area in [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/barahasoft.com.np\/blog\/android-bottom-sheet-customization\/\" \/>\n<meta property=\"og:site_name\" content=\"BS Blog\" \/>\n<meta property=\"article:published_time\" content=\"2020-09-30T00:52:09+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-09-30T01:57:08+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/barahasoft.com.np\/blog\/wp-content\/uploads\/2020\/09\/customized_bottom_sheetjpg.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"500\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/barahasoft.com.np\/blog\/#website\",\"url\":\"https:\/\/barahasoft.com.np\/blog\/\",\"name\":\"BS Blog\",\"description\":\"Baraha Soft Blog\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/barahasoft.com.np\/blog\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/barahasoft.com.np\/blog\/android-bottom-sheet-customization\/#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/barahasoft.com.np\/blog\/wp-content\/uploads\/2020\/09\/customized_bottom_sheetjpg.jpg\",\"width\":1200,\"height\":500,\"caption\":\"Barahasoft\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/barahasoft.com.np\/blog\/android-bottom-sheet-customization\/#webpage\",\"url\":\"https:\/\/barahasoft.com.np\/blog\/android-bottom-sheet-customization\/\",\"name\":\"Android Bottom Sheet Customization - BS Blog\",\"isPartOf\":{\"@id\":\"https:\/\/barahasoft.com.np\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/barahasoft.com.np\/blog\/android-bottom-sheet-customization\/#primaryimage\"},\"datePublished\":\"2020-09-30T00:52:09+00:00\",\"dateModified\":\"2020-09-30T01:57:08+00:00\",\"author\":{\"@id\":\"https:\/\/barahasoft.com.np\/blog\/#\/schema\/person\/4f97ce15b5eda1cd9fc64e3362dca065\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/barahasoft.com.np\/blog\/android-bottom-sheet-customization\/\"]}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/barahasoft.com.np\/blog\/#\/schema\/person\/4f97ce15b5eda1cd9fc64e3362dca065\",\"name\":\"Mahen\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/barahasoft.com.np\/blog\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/2d90f77c4da8e61f15085bfd7b473714?s=96&d=mm&r=g\",\"caption\":\"Mahen\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","ads":{"ads-top":"","ads-top-link":"","ads-bottom":"","ads-bottom-link":"","ads-side-top":"","ads-side-top-link":"","ads-side-bottom":"","ads-side-bottom-link":""},"_links":{"self":[{"href":"https:\/\/barahasoft.com.np\/blog\/wp-json\/wp\/v2\/posts\/144"}],"collection":[{"href":"https:\/\/barahasoft.com.np\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/barahasoft.com.np\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/barahasoft.com.np\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/barahasoft.com.np\/blog\/wp-json\/wp\/v2\/comments?post=144"}],"version-history":[{"count":10,"href":"https:\/\/barahasoft.com.np\/blog\/wp-json\/wp\/v2\/posts\/144\/revisions"}],"predecessor-version":[{"id":159,"href":"https:\/\/barahasoft.com.np\/blog\/wp-json\/wp\/v2\/posts\/144\/revisions\/159"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/barahasoft.com.np\/blog\/wp-json\/wp\/v2\/media\/151"}],"wp:attachment":[{"href":"https:\/\/barahasoft.com.np\/blog\/wp-json\/wp\/v2\/media?parent=144"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/barahasoft.com.np\/blog\/wp-json\/wp\/v2\/categories?post=144"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/barahasoft.com.np\/blog\/wp-json\/wp\/v2\/tags?post=144"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}