Getting to grips with android development

Action Bar

After fooling around with the excellent app inventor, I thought I should branch out in to real android apps.  I downloaded Android Studio and looked at the first tutorials.

Getting the Action Bar working in the second tutorial drove me nuts.  These are the rather hidden, not to say missing things from that tutorial.

  1. The openSearch() and openSettings() functions are missing and you are expected to add them.  I googled this and found a nice placeholder for a function thusly:
        private void openSearch() {
            Toast.makeText(this, "Search button pressed", Toast.LENGTH_SHORT).show();
        }
    
  2. The icons have to be added manually.  You follow the hint and download the Action Bar Icon Pack.  Then you find the icon you want and copy all the drawable-xxxxx subfolders for that icon in to the project on the same level as the drawable folder in the project structure.  Android Studio automagically includes the right image in the right place.
  3. Finally, the icons will not appear if the main java class extends android.support.v7.app.ActionBarActivity.  It only needs to extend Activity (this is my guess, I can’t find it anywhere, but it works), but you do need the minimum API (set in the build.gradle to be 11…

Madness, but I got there.  This is all impossibly Greek to me still, but I did get it to work, so that is progress.

Things to remember:

  • the funcion in the java code is connected to the button xml through the android:onclick parameter!   Very neat.