0% found this document useful (0 votes)
6 views

Android Resources Unit 5

The document discusses different types of resources used in Android applications including strings, styles, dimensions, images, and more. It explains how resources are stored and organized in the res folder and subdirectories. It also covers providing alternative resources for different configurations like landscape/portrait, languages, and qualities. The document discusses using styles, themes, and inheritance for styling Android apps.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Android Resources Unit 5

The document discusses different types of resources used in Android applications including strings, styles, dimensions, images, and more. It explains how resources are stored and organized in the res folder and subdirectories. It also covers providing alternative resources for different configurations like landscape/portrait, languages, and qualities. The document discusses using styles, themes, and inheritance for styling Android apps.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 106

Mobile Application

Development
By,
Prof. Himanshu H Patel,
Prof. Hiten M Sadani
U. V. Patel College of Engineering, Ganpat University

1
Android Resources

2
What Are Resources?

• All Android applications are composed of two things: functionality


(code instructions) and data (resources). The functionality is the code
that determines how your application behaves. This includes any
algorithms that make the application run. Resources include text
3

strings, styles and themes, dimensions, images and icons, audio files,
videos, and other data used by the application.
Storing Application Resources

• Android resource files are stored separately from the .java/Kotlin


class files in the Android project. Most common resource types are
stored in XML. You can also store raw data files and graphics as
resources. Resources are organized in a strict directory hierarchy. All
4

resources must be stored under the /res project directory in


specially named subdirectories whose names must be lowercase.
• Different resource types are stored in different directories. The
resource subdirectories generated when you create an Android
project
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
View Binding

35
View Binding

36
View Binding

37
View Binding

38
Android Resources:

What Are Resources?

•All Android applications are composed of two things: functionality


(code instructions) and data (resources). The functionality is the code
that determines how your application behaves. This includes any
algorithms that make the application run. Resources include text
strings, styles and themes, dimensions, images and icons, audio files,
videos, and other data used by the application.

39
Storing Application Resources
•Android resource files are stored separately from the .java/.kotlin class
files in the Android project. Most common resource types are stored in
XML.
•You can also store raw data files and graphics as resources. Resources
are organized in a strict directory hierarchy.
•All resources must be stored under the /res project directory in
specially named subdirectories whose names must be lowercase.
•Different resource types are stored in different directories. The
resource subdirectories generated when you create an Android project

40
Storing Application Resources

41
Storing Application Resources

42
Storing Application Resources

43
Storing Application Resources

44
Storing Application Resources

45
Storing Application Resources

46
String resources:

47
String resources:

48
Providing alternative resources

49
Providing alternative resources

50
Providing alternative resources

51
Qualifier name rules:

52
Qualifier name rules:

53
Qualifier name rules:

54
Qualifier name rules:

55
Color:

56
Color:

It is important to note that the most current way of accessing color resources
(since API 24) requires providing context in order to resolve any
custom theme attributes.
57
https://html-color-codes.info/colors-from-image/
Providing alternative resources

58
Providing alternative resources

59
Providing alternative resources

60
Portrait vs landscape

61
Portrait vs landscape

62
Portrait vs landscape
Determining Configuration at Runtime

63
Providing alternative resources-Dimension

64
Providing alternative resources-Dimension

65
Providing alternative resources-Dimension

66
Providing alternative resources-Dimension

67
Providing alternative resources-Dimension

68
Providing alternative resources-Dimension

69
Providing alternative resources-Dimension

70
Providing alternative resources-Dimension

71
Providing alternative resources-Dimension

72
alternative resources-Multi Language

73
alternative resources-Multi Language

74
Layout Direction

75
Font:

76
Android Style:

77
Android Style:

78
Android styling: themes vs styles

79
Android styling: themes vs styles

80
Android styling: themes vs styles

As you can see, each of the keys in the style are things
you could set in a textview:
81
Android styling: themes vs styles

Extracting them to a style makes it easy to reuse across


multiple views and maintain.
82
Android styling: themes vs styles

Extracting them to a style makes it easy to reuse across


multiple views and maintain.
83
Android styling: themes vs styles

84
Android styling: themes vs styles

85
Android styling: themes vs styles

86
Android styling: themes vs styles

87
Android styling: themes vs styles

88
Android styling: themes vs styles

89
Android styling: themes vs styles

90
Android style: inheritance

91
Android style: inheritance

92
Android style: inheritance

93
Android style: inheritance

94
Android style: inheritance

95
Material 2.0 Theme Android style: inheritance

96
Menu:

97
Menu:

98
Menu:

99
Contextual Menus

100
Context Menu
• A contextual menu offers actions that affect a specific item or context
frame in the UI.
• You can provide a context menu for any view, but they are most often
used for items in a ListView, GridView, or other view collections in which
the user can perform direct actions on each item.
• There are two ways to provide contextual actions:
• floating context menu.
• contextual action mode.

101
Creating a floating context menu

102
Creating a floating context menu
• To provide a floating context menu:
• Step 1:
• Register the View to which the context menu should be associated by
calling registerForContextMenu() and pass it the View.
• If your activity uses a ListView or GridView and you want each item to
provide the same context menu, register all items for a context menu by
passing the ListView or GridView to registerForContextMenu().
• Step 2:
• Implement the onCreateContextMenu() method in your Activity or
Fragment.
• When the registered view receives a long-click event, the system calls
your onCreateContextMenu() method. This is where you define the menu
103
items, usually by inflating a menu resource. For example:
Creating a floating context menu

override fun onCreateContextMenu(menu: ContextMenu, v: View,


menuInfo: ContextMenu.ContextMenuInfo) {
super.onCreateContextMenu(menu, v, menuInfo)
val inflater: MenuInflater = menuInflater
inflater.inflate(R.menu.context_menu, menu)
}

104
Creating a floating context menu
• Step 3:
• Implement onContextItemSelected().
• When the user selects a menu item, the system calls this method so you
can perform the appropriate action. For example:
override fun onContextItemSelected(item: MenuItem): Boolean {
val info = item.menuInfo as AdapterView.AdapterContextMenuInfo
return when (item.itemId) {
R.id.edit -> {
editNote(info.id)
true
}
R.id.delete -> {
deleteNote(info.id)
true
}
else -> super.onContextItemSelected(item)
}
105
}
alternative resources-Site references
https://developer.android.com/develop/ui/views/components/menus

https://appicon.co/#app-icon

https://www.canva.com/

https://colorhunt.co/

https://material.io/resources/devices/

106

You might also like