AND-801 practice question 2 of 10

Which of the below choices is the best answer to fill the empty space in the following sentence? If you want to give all text widgets in an app the…

Full set: 45 questions
Which of the below choices is the best answer to fill the empty space in the following sentence? If you want to give all text widgets in an app the same format such as font color, font size, and font family, you should add the style attribute to the TextView XML tags in layout file and set the attribute value to the same style name. You should define that style by adding a new style tag "style name- style_name" inside...............................
Answer options
A: AadroiddManifest-xml file
B: activity_main.xml file
C: stytes.xml file Correct answer
D: MainActivity.java or MainActivity.kt file
Correct Answer:
C. stytes.xml file
Explanation

In Android development, styles and themes are defined as XML resources in a dedicated file within the res/values/ directory. The conventional filename for this purpose is styles.xml (or themes.xml). Defining a style in this central location allows it to be reused across multiple layouts and views throughout the application, ensuring a consistent look and feel. This practice separates the UI's design (style) from its structure (layout), which is a fundamental principle of robust Android app architecture. The style is then applied to a View in a layout file using the style attribute, for example, style="@style/stylename".

Why Incorrect

A. AndroidManifest.xml file: This file is used to declare the application's components, permissions, and other essential metadata, not for defining UI style resources.
B. activitymain.xml file: This is a layout file that defines the structure of a user interface for a specific activity. It is not the standard location for defining app-wide, reusable styles.
D. MainActivity.java or MainActivity.kt file: These are source code files for implementing application logic. UI styles are defined declaratively in XML resources, not programmatically within Java or Kotlin code.

References

1. Official Android Developer Documentation: "A style is defined in an XML resource that is separate from the XML that specifies the layout. This XML file resides in your project's res/values/ directory... The name of the XML file is arbitrary, but it is conventionally named styles.xml."

Source: Google LLC. (2023). Styles and themes. Android Developers. Retrieved from https://developer.android.com/guide/topics/ui/look-and-feel/themes#DefiningStyles, Section: "Defining styles".

2. University Courseware (related material): In materials for teaching Android development, the standard practice is emphasized. For example, in the "Developing Android Apps with Kotlin" course, it is stated that styles are resources defined in XML.

Source: Google. (2022). Use themes and styles. Android Basics in Kotlin. Retrieved from https://developer.android.com/codelabs/android-basics-kotlin-affirmations-app-polish#3, Step 3: "Create a theme and styles". This codelab, used in educational settings, directs the user to create and modify styles within themes.xml (a file analogous to styles.xml) in the res/values directory.

3. Peer-Reviewed Academic Publication (related context): Research on Android development practices highlights the importance of resource externalization for maintainability. Styles are a key type of externalized resource.

Source: Linares-Vásquez, M., Bavota, G., & Poshyvanyk, D. (2014). An empirical study on the quality of android applications. Proceedings of the 11th Working Conference on Mining Software Repositories, 2-11. https://doi.org/10.1145/2597073.2597092. The paper discusses the analysis of Android resources (res/ directory), which implicitly supports the standard practice of separating concerns, such as defining styles in res/values/.

Scroll to Top