Building Android Apps With Python - Part - 1
Building Android Apps With Python - Part - 1
Introduction
Are you curious about developing android apps but Java is not
your companion? Android universe is mainly build using Java,
Kotlin, Flutter, and Corona using Lua Scripting Language (mainly
gaming engine, used in games like angry birds) but in recent
times, Python has made its way into every domain and android is
no different. In this series of articles, we will look at how to set-up
the required environment, the basics of developing an android
app, referencing the documentation, and how to move ahead with
your projects.
We will use Kivy a lot for the front-end of the application but with
another package and why we require that package will be covered
shortly.
Image by author
Let’s code!
The part you have been waiting for so long is here. I am using
Pycharm IDE for coding because it’s easy to code for me, but you
can use VSCode, Sublime, or spyder as per your wish. Before I
start, we need to understand some points here:
1. An android app has a front-end (UI/UX) or the
interactive part where the user interacts with your
application and all the inputs are given via this layer.
Now quickly open up your IDE and start with this basic code of
Hello World!
1. The first line imports the base app from the Kivy library.
4. def build function is the app entry point. All the things
defined here will be built first and the first screen or the main
screen is passed here. It returns the Label, and it has a property
of text which has the value “Hello World”. Read more about
labels here.
5. Then the last line calls this main class and runs it.
This how we build our first app but did you notice one thing that
the background is automatically black and text is white? I haven’t
even mentioned this in the code. Kivy takes it by default. Now we
move to the interesting part, let’s build a simple button with no
enhancement in Kivy:
Don’t grasp the code as it is beyond your scope for now but just
look at the output now:
Image by author
Now we have talked a lot about Kivy and we know it provides the
platform for building applications. KivyMD is a collection of
Material Design compliant widgets for use with Kivy and
approximately Google’s Material Design spec as close as possible
without sacrificing ease of use or application performance. It is
based on Kivy and is easier to code. It is very similar to Kivy and
just adds MD at starting in every element and widget, plus it has a
wide variety of other new elements. Now see the code in Kivymd to
generate the same output button:
Try to run this script and you will see the same output as returned
by long Kivy code.
GitHub: Link