Ad Code

Bottom Sheet in Sketchware

Bottom Sheet in Sketchware

In this tutorial you are going to learn how to create bottom sheet and how to add widget in it and give it functions and also customization of bottom sheet too


1. Design the main.xml the way you please, but in this tutorial I made a simple design for the xml. 


2. Create a custom view and name it get and design it.


Note : you will have to set the check the check box


3. On button click (I'm referring to the button on the main activity) add this code


final com.google.android.material.bottomsheet.BottomSheetDialog Bs = new com.google.android.material.bottomsheet.BottomSheetDialog(MainActivity.this);
View lay = getLayoutInflater().inflate(R.layout.get, null); Bs.setContentView(lay);
Bs.setCancelable(false);
Bs.getWindow().findViewById(R.id.design_bottom_sheet).setBackgroundResource(android.R.color.transparent);
LinearLayout l1 = (LinearLayout)lay.findViewById(R.id.linear1);
Button b1 = (Button)lay.findViewById(R.id.button1);
CheckBox c1 = (CheckBox)lay.findViewById(R.id.checkbox1);
TextView t1 = (TextView)lay.findViewById(R.id.textview1);
int[] colorsCRNYC = { Color.parseColor("#ecf0f1"), Color.parseColor("#ecf0f1") }; android.graphics.drawable.GradientDrawable CRNYC = new android.graphics.drawable.GradientDrawable(android.graphics.drawable.GradientDrawable.Orientation.TOP_BOTTOM, colorsCRNYC);
CRNYC.setCornerRadii(new float[]{(int)50,(int)50,(int)50,(int)50,(int)0,(int)0,(int)0,(int)0});
CRNYC.setStroke((int) 0, Color.parseColor("#000000"));
l1.setElevation((float) 5);
l1.setBackground(CRNYC);
t1.setText("This is Bottom Sheet");
c1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton _param1, boolean _param2)  {
final boolean _isChecked = _param2;
if (_isChecked) {
check = "Check box was ticked";
}
else {
check = "Check box wasn't ticked";
}
}
});
c1.setChecked(false);
b1.setOnClickListener(new OnClickListener() { public void onClick(View v) {
textview1.setText(check);
Bs.hide(); } });
Bs.show();


4. Create a string and name it "check" and run the project

5. And you're all done, now you will be able to show your bottomsheet successfully.


Post a Comment

0 Comments

Ad Code