We need to remember some points before code Android Apps. The points are given below.
- Package - A package is a namespace. A package is essentially the directory (folder) to which source code belongs. Normally, this is a directory structure that uniquely identifies your application; such as com.helloworld.app. Then you can create packages within your application package that separates your code; such as com.helloworld.app.ui or com.helloworld.app.data. It basically lets you have two classes named Employee if they are in different packages.
- Class - A class is a blueprint for creating objects in class-based object-oriented programming; you should learn the basics of OOP and understand what an object is, what a class is, what is inheritance, polymorphism, encapsulation before learning anything else about Java.
- The basic structure for one of the Android project-
Let's Explore each file
- AndroidManifest.xml: This is the Android definition file. It contains information about the Android application such as minimum Android version, permission to access Android device capabilities such as in, internet access permission, ability to use phone permission, etc.
Example :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.abnhive.helloworld">
<uses-sdk android:minSdkVersion="7" />
<application
android:versionCode="1"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
- java: This folder contains the Java source files with classes and package files.
- res: Here we can store resource files such as pictures, XML files for defining layouts, and so forth. Within this folder, there are additional folders such as Drawable, Layout, and Values.
- build.gradle: This defines your build configuration that applies to all modules.
Inside res Folder
- drawable: A Drawable folder contains resource type files like Bitmap (PNG, JPEG), Nine Patch, Vector (XML), Shape, Layers, States, Levels, and Scale.
- layout: A layout defines the visual structure for a user interface, such as the UI for an Android application. This folder stores Layout files that are written in XML language. Stay tuned for android layouts article.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World" />
<Button android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click Me!" />
</LinearLayout>
- mipmap: Mipmap folder contains the Image Asset file that can be used in Android Studio application. like Launcher icons, Action bar and tab icons, and Notification icons.
- colors.xml: contains colour resources of the Android application. Colours are defined in hexadecimal format.
Example :
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3ACD7A</color>
<color name="colorPrimaryDark">#098B41</color>
<color name="colorAccent">#9E3DC1</color>
</resources>
- strings.xml: We can create strings and their names for the application. The string value is identified by a unique name that can be used in the Android application program
Example :
<resources>
<string name="app_name">ABNHive</string>
</resources>
- styles.xml: contains resources of the theme style in the Android application. We can create our own themes for each segment.
Example :
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
- Aswin Bhim Nath
Comments
Post a Comment