OnClickListener, create custom buttons
activity_main.xml -> add CustomView -> search FloatingActionButton
- Add the following to res -> values -> styles.xml
<style name="Theme.MaterialButton" parent="AppTheme">
<item name="colorAccent">@color/light_red</item>
<item name="colorButtonNormal">@color/dark_red</item>
</style>
- Add the following to button XML
style="@style/Widget.AppCompat.Button.Colored"
android:theme="@style/Theme.MaterialButton"
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//perform action
}
});
ALTERNATIVE METHOD:
- Add "buttonClicked" method to android:onClick="" within XML layout file
- Write buttonClicked method within corresponding activity