Android Buttom sheet is not working -
android bottom sheet not working. below code , want create bottom sheet demo not working , bottom sheet not showing.
public class mainactivity extends appcompatactivity implements view.onclicklistener{ private bottomsheetbehavior mbottomsheetbehavior; private button button1; private view bottomsheet; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); getid(); setlistner(); mbottomsheetbehavior = bottomsheetbehavior.from(bottomsheet); } private void getid() { try { button1 = (button)findviewbyid(r.id.button1); bottomsheet = findviewbyid(r.id.bottom_sheet); } catch (exception e) { e.printstacktrace(); } } private void setlistner() { try { button1.setonclicklistener(this); } catch (exception e) { e.printstacktrace(); } } @override public void onclick(view v) { try { switch (v.getid()) { case r.id.button1: mbottomsheetbehavior.setstate(bottomsheetbehavior.state_expanded); log.e("buttom clicked",">>"); break; } } catch (exception e) { e.printstacktrace(); } } }
here xml file.
<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"> <scrollview android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior"> <linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:paddingtop="24dp"> <button android:id="@+id/button1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="button 1" android:padding="16dp" android:layout_margin="8dp" android:textcolor="@android:color/white" android:background="@android:color/holo_green_dark"/> </linearlayout> </scrollview> <android.support.v4.widget.nestedscrollview android:id="@+id/bottom_sheet" android:layout_width="match_parent" android:layout_height="350dp" android:cliptopadding="true" android:background="@android:color/holo_orange_light" app:layout_behavior="android.support.design.widget.bottomsheetbehavior" > <imageview android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/ic_launcher" android:padding="16dp" android:textsize="16sp"/> </android.support.v4.widget.nestedscrollview> </android.support.design.widget.coordinatorlayout>
actually want implement bottom sheet using android support library 23.2
using abouve code without out using other library not working. , advance.
use dependency compile 'com.cocosw:bottomsheet:1.2.0'
and add code
new bottomsheet.builder(getactivity(), r.style.bottomsheet_styledialog). sheet(r.menu.bottom_sheet).title(displayname).listener(new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface dialog, int which) { switch (which) { case r.id.btnone: // something... break; case r.id.btntwo: // ... } } }).show();
Comments
Post a Comment