3. Defining Application Metadata:
- Application Manifest also contains information such as app name, icon, theme, and version.
Example of app metadata:
<application
android:name=“.MyApplication”
android:icon=“mipmap/ic_launcher”
android:label=“string/app_name”
android:theme=“style/AppTheme”>
</application>
8. Application Resources: Assets for User Interface
The Android app stores resources such as strings, images, fonts, and UI layouts in the /res directory. These resources are managed separately from the program code, allowing you to easily customize the app for different devices, languages, and screen orientations.
Types of Resources
1. String: Text used in the app, such as titles, messages, or labels.
Stored in res/values/strings.xml.
Example:
<string name=“app_name”>My App</string>
<string name=“welcome_message”>Welcome to My App!</string>
2. Images: Visual assets such as icons, background images, or illustrations.
Stored in res/drawable/ or res/mipmap/.
Examples: ic_launcher.png, background.jpg.
3. (Layout) Layout: An XML file that defines the structure of the user interface.
Stored in res/layout/.
Examples: activity_main.xml, fragment_detail.xml.
4. Color: The definition of the color used in the application.
Stored in res/values/colors.xml.
Example:
<color name=“primary_color”>6200EE</color>
<color name=“secondary_color”>03DAC6</color>
5. Dimensions: The size and padding used in the layout.
Stored in res/values/dimens.xml.
Example:
<dimen name=“padding_small”>8dp</dimen>
<dimen name=“text_size_large”>24sp</dimen>
Accessing Resources through Class R
When an app is compiled, Android automatically generates an R class that contains references to all resources defined in the /res directory. You can access these resources through the R class in the program code.
Example of Accessing Strings:
String appName = getString(R.string.app_name);
Example of Accessing Images:
ImageView imageView = findViewById(R.id.my_image_view);
imageView.setImageResource(R.drawable.ic_launcher);
Example of Accessing a Layout:
setContentView(R.layout.activity_main);
Other Interesting Articles
Conclusion
By understanding the key components like Activity, Fragment, Intent, and Service, you can build more efficient, modular, and manageable Android apps. Each component has a specific role that allows the app to function properly, both in the foreground and in the background.
Additionally, components such as Broadcast Receiver and Content Provider allow your app to respond to system changes and share data with other apps.
By leveraging Application Manifest and Application Resources, you can define the structure of your application and manage assets such as strings, images, and layouts in a more organized way.