How to Create Material Button in Sketchware
//Add this oncreate event
// MaterialButton without Stroke
final com.google.android.material.button.MaterialButton btn1 = new com.google.android.material.button.MaterialButton(this, null, R.attr.borderlessButtonStyle);
linear1.addView(btn1);
btn1.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
btn1.setPadding(20,8,20,8);
//left, top, right, bottom
btn1.setGravity(Gravity.CENTER);
btn1.setText("MATERIAL BUTTON WITHOUT STROKE");
btn1.setTextColor(Color.parseColor("#03A9F4"));
btn1.setCornerRadius(10);
btn1.setClickable(true);
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showMessage("button1 clicked");
}
});
_setMaterialEffect(btn1, "#B3E5FC");
// MaterialButton with Stroke
final com.google.android.material.button.MaterialButton btn2 = new com.google.android.material.button.MaterialButton(this, null, R.attr.borderlessButtonStyle);
linear1.addView(btn2);
btn2.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
btn2.setPadding(20,8,20,8);
//left, top, right, bottom
btn2.setGravity(Gravity.CENTER);
btn2.setText("MATERIAL BUTTON WITH STROKE");
btn2.setTextColor(Color.parseColor("#03A9F4"));
btn2.setCornerRadius(10);
btn2.setStrokeWidth(1);
btn2.setStrokeColor(android.content.res.ColorStateList.valueOf(Color.parseColor("#BDBDBD")));
btn2.setClickable(true);
btn2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showMessage("button2 clicked");
}
});
_setMaterialEffect(btn2, "#B3E5FC");
//Add this in MoreBlock
android.content.res.ColorStateList colorStateListRipple = new android.content.res.ColorStateList(new int[][] {{0}}, new int[] {
Color.parseColor(_color.toString())
});
android.graphics.drawable.RippleDrawable rippleDrawable = (android.graphics.drawable.RippleDrawable)_view.getBackground();
rippleDrawable.setColor(colorStateListRipple);
_view.setBackground(rippleDrawable);
Comments
Post a Comment