FAB – Floating Action Button

A floating action button (FAB) performs the primary, or most common, action on a screen. It appears in front of all screen content, typically as a circular shape with an icon in its center. FABs come in three types: regular, mini, and extended.

Only use a FAB if it is the most suitable way to present a screen’s primary action.

FloatingActionButton fabButton = findViewById(R.id.fab); // Replace 'fab' with View id

fabButton.setOnClickListener(new View.OnClickListener() { // Set onClickListener
    @Override
    public void onClick(View view) {
        // Create a new intent to start another Activity
        Intent addNewIntent = new Intent(MainActivity.this, NewActivity.class);
        startActivity(addNewIntent);
    }
 });

ud851-Exercises-student\Lesson09-ToDo-List\T09.01

Create Menu in ActionBar

Create a menu in the ActionBar. Can be in the main bar or under the menu icon.

Create 'main.xml' in 'menu' folder in 'res' if does not exist.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <item android:id="@+id/action_search" // Add an item tag for each item in the menu
        android:title="@string/search"
        android:orderInCategory="1" // Order item will show in menu list
        app:showAsAction="ifRoom" // "ifRoom" will display menu item in ActionBar if room
        />

</menu>

Override onCreateOptionsMenu in Activity Java file.

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

Override onOptionsItemSelectedin Activity Java file.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int menuItem = item.getItemId();
    if (menuItem == R.id.action_search) { // Change 'action_search' to id of menu layout item
        Context context = MainActivity.this; // Change 'MainActivity' to current Activity
        CharSequence text = "Click handled"; // What happens when menu item is clicked
        int duration = Toast.LENGTH_SHORT; // What happens when menu item is clicked
        Toast toast = Toast.makeText(context, text, duration); // What happens when menu item is clicked
        toast.show(); // What happens when menu item is clicked
        return true;
    }
    return super.onOptionsItemSelected(item);
}

ud851-Exercises-student\Lesson02-GitHub-Repo-Search\T02.06-Exercise-AddPolish