Topic 3: User Interfaces Part 1
(Authors: Dr Caspar Ryan, Dr Ermyas Abebe, Mr. Keith Foster)
Semester 1, 2019 COSC2309/2347 Mobile Application Development Topic 3, Slide 1
• •
Creating a User Interface
Activity is the basic building block of the UI (Complemented by Fragments in Android API 11+)
There are two ways to create UI in Android
Programmatic: Writing Java Code to declare UI Object and their layouts (Like AWT and Swing)
Declarative: Using XML to declare UI similar to creating Web Pages with HTML or JavaFX. (Preferred Option where possible since it separates presentation from behaviour)
– XML is compiled into a View Resource and linked using an automatically
1
generated “R.java” file.
2
Semester 1, 2019 COSC2309/2347 Mobile Application Development Topic 3, Slide 2
Hello World
Simple GUI example: Create an Activity class which contains the layout, and handles click events to the button
HelloAndroid.java Activity
attach listener to button
Semester 1, 2019
COSC2309/2347 Mobile Application Development Topic 3, Slide 3
onClick() callback when button is clicked
Views and View Groups
• android.view.View and its subclasses e.g. TextView, Button, Checkbox, EditText etc.
• Composite/container widgets extend android.view.ViewGroup e.g. Spinner, ListView, RecyclerView, ScrollView, DatePicker, TimePicker, DrawerLayout etc.
• Add child View widgets to a ViewGroup programmatically using the method
ViewGroup.addView(View child)
• Add child objects in layout XML to a ViewGroup by
nesting View elements
• Use new Android Studio Tools->Layout Inspector or
• View instances can have an id so they can be identified programmatically e.g. android:id=”@+id/xyz_id”
“@” refers to another resource, “+” indicates resource creation (add to R.java) not needed for @android: (android.R) resources
Semester 1, 2019
COSC2309/2347 Mobile Application Development Topic 3, Slide 4
R.java
• In order to inspect R.java you can find it as follows:
• In Project View
moduleName/build/generated/not_namespaced_r_class_sources/debug /r/package.x.y/R.java
• Must not be edited since it is auto generated
• Note that the package it resides in is declared in
AndroidManifest.xml
• Occasionally Android Studio can generate the wrong import so is worth knowing where it resides so you can ensure import is correct!
Semester 1, 2019 COSC2309/2347 Mobile Application Development Topic 3, Slide 5
Layout Management
Layout has TWO meanings in Android
1. Explicitly named Layout subclasses of
android.view.ViewGroup
– android.widget.LinearLayout, RelativeLayout, FrameLayout, TableLayout, AbsoluteLayout (deprecated), GridLayout (API Level 14+), DrawerLayout, ConstraintLayout etc.
– may be nested to provide more complex layout behaviour
– don’tprovideexplicitUIbehaviour(i.e.interaction)otherthanlaying
out other UI components (View or ViewGroup)
– NOTE:othernon-layoutViewGroupcomponentshavelayoutlike functionality e.g. Gallery, GridView, ImageSwitcher, ScrollView,TabHost,ListView, RecyclerView etc.
Semester 1, 2019 COSC2309/2347 Mobile Application Development Topic 3, Slide 6
Layout Management
2. Layout resources which are XML files in the project res/layout directory
– LayoutclassesXYZLayout(1)areoptionalinlayoutresourcefiles(2)
– canembedaViewina“layout”XMLfilewithoutembeddingitina
Layout ViewGroup
– Layout resources are associated with an activity using Activity.setContentView(int layoutResID)e.g. setContentView(R.layout.hello_world); where hello_world matches the filename of the layout resource hello_world.xml
– associated with a Fragment using the inflater passed to Fragment.onCreateView()
Semester 1, 2019 COSC2309/2347 Mobile Application Development Topic 3, Slide 7
Layout Resources
• Layout resources are declared as XML elements in a layout resource file in the project res/layout directory (see slide 2)
• All layouts have basic layout XML attributes which apply to the Layout itself or ALL child View items within that layout
– these are declared within the Layout class itself
– see XML attributes in API docs
• There are also layout attributes that apply to individual Views within a Layout (i.e. advise parent how View wants to be laid out)
– Basic per view layout attributes are shared by all ViewGroup classes
– see android.view.ViewGroup.LayoutParams and
ViewGroup.MarginLayoutParams
– or per view layout attributes for specific layout classes e.g. LinearLayout.LayoutParams or FrameLayout.LayoutParams
Semester 1, 2019 COSC2309/2347 Mobile Application Development Topic 3, Slide 8
Layout Resources (contd.)
From: https://developer.android.com/guide/topics/ui/declaring-layout.html
Semester 1, 2019 COSC2309/2347 Mobile Application Development Topic 3, Slide 9
Layout Resources (contd.)
• The LayoutParams classes also declare constants related to the value of XML attributes that are used internally for layout purposes e.g. MATCH_PARENT, WRAP_CONTENT (see API for specific values, constraints etc.) .. Note CASE difference between constants and XML constant values
(match_parent, wrap_content)!
• set XML constant values using XML attribute syntax as follows:
– android:layout_attribute_name=”constant_value” – NOTE: layout_width and layout_height must be
explicitly specified
– These are declared in ViewGroup.LayoutParams
Semester 1, 2019 COSC2309/2347 Mobile Application Development Topic 3, Slide 10
Example Layout Attributes
XML Attributes for ViewGroup.LayoutParams
Attribute Name
Related Method
Description
android:layout_height
N/A
Specifies the basic height of the view.
android:layout_width
N/A
Specifies the basic width of the view.
XML Attributes for ViewGroup.MarginLayoutParams
Attribute Name
Related Method
Description
android:layout_marginBottom
setMargins(int,int,int,int)
Specifies extra space on the bottom side of this view.
android:layout_marginLeft
setMargins(int,int,int,int)
Specifies extra space on the left side of this view.
android:layout_marginRight
setMargins(int,int,int,int)
Specifies extra space on the right side of this view.
android:layout_marginTop
setMargins(int,int,int,int)
Specifies extra space on the top side of this view.
Semester 1, 2019 COSC2309/2347 Mobile Application Development Topic 3, Slide 11
Layout Management
Simple GUI example: Create XML UI Layout gets compiled and referenced through R.java main.xml (XML file containing layout)
R.java (auto-generated)
layout compiled and identified by a resource id in the auto- generate R.java
NOTE: The system has its own generated android.R class
Semester 1, 2019
COSC2309/2347 Mobile Application Development
Topic 3, Slide 12
Declarative and Programmatic Access
• Declarative UI resources must be first loaded into memory before they can be used
– e.g. accessed and manipulated programmatically
– associated directly with an Activity
– This is called Inflating in Android (instantiation might be a better word)
• To associate a layout file with an Activity use android.app.Activity.setContentView(int layoutResID)
– this inflates the layout XML and makes it visible
– must be called before any other references to UI (View or layout) resources
e.g. View android.app.Activity.findViewById(int id)
• In other cases where you want to instantiate View objects from XML but not
associate with an Activity use a LayoutInflater
• e.g. LayoutInflater inflater = (LayoutInflater)
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ListView listview = (ListView) inflater.inflate(R.layout.listview, …);
• associated with a Fragment using inflater passed to Fragment.onCreateView()
• In general, use declarative access for layout and configuration and programmatic
access to dynamically generate content at runtime
Semester 1, 2019 COSC2309/2347 Mobile Application Development Topic 3, Slide 13
Building an Android GUI (echo.xml)
Building an Android GUI
• When building an Android GUI there are two different views
• Design View
– Use the graphical UI builder tools to drag and drop and set various attributes
– Can immediately preview result and configure the target device
– Does not always work as expected and has been known to completely destroy layouts mid way through!
– NOTE: Should always test on emulator and ideally a real target device
– Is potentially buggy https://stackoverflow.com/questions/50929640/android-studio-3-1-
3-design-view-is-always-empty
• Text View
– Edit resource XML directly
– This gives the most control and is useful for learning how the XML works
– Basic knowledge of the XML structure/operation is still necessary to use the Design view
– Easier to map XML directly to APIs
• Switching between views where appropriate is probably the best approach for most people
Semester 1, 2019 COSC2309/2347 Mobile Application Development Topic 3, Slide 15
LinearLayout
java.lang.Object
↳
android.view.View
↳
android.view.ViewGroup
↳
android.widget.LinearLayout
• Lays out child View widgets in a linear direction [vertically or horizontally (default)]
• Can be nested (see image to right) but consider RelativeLayout as an alternative if nesting gets complicated
– see lint warnings re: performance of this example
• LinearLayout has specific attributes (see
next slide)
• Child specific layout attributes (see
LinearLayout.LayoutParams) e.g weight which specifies child (re)sizing
Semester 1, 2019 COSC2309/2347 Mobile Application Development Topic 3, Slide 16
LinearLayout Attributes
Attribute Name
Related Method
Description
android:baselineAligned
setBaselineAligned(boolean)
When set to false, prevents the layout from aligning its children’s baselines.
android:baselineAlignedChildIndex
setBaselineAlignedChildIndex(int)
When a linear layout is part of another layout that is baseline aligned, it can specify which of its children to baseline align to (that is, which child TextView).
android:gravity
setGravity(int)
Specifies how to place the content of an object, both on the x- and y-axis, within the object itself.
android:measureWithLargestChild
When set to true, all children with a weight will be considered having the minimum size of the largest child.
android:orientation
setOrientation(int)
Should the layout be a column or a row? Use “horizontal” for a row, “vertical” for a column.
android:weightSum
Defines the maximum weight sum.
• See API docs for attributes inherited from android.view.View and android.view.ViewGroup and also LinearLayout.LayoutParams and its inherited attributes
• NOTE: difference between layout_gravity (LayoutParams) and gravity!
Semester 1, 2019 COSC2309/2347 Mobile Application Development Topic 3, Slide 17
LinearLayout and layout_weight
• When using layout_weight (from LinearLayout.LayoutParams) to set proportional spacing of children:
• If in a vertical layout then set layout_height of each child view to 0dp and higher weight for more proportional vertical spacing
• If in a horizontal layout then set layout_width of each child view to 0dp and again higher weight for more proportional horizontal spacing
• See https://developer.android.com/guide/topics/ui/layout/linear. html#Weight
Semester 1, 2019 COSC2309/2347 Mobile Application Development Topic 3, Slide 18
RelativeLayout
java.lang.Object
↳
android.view.View
↳
android.view.ViewGroup
↳
android.widget.RelativeLayout
• Places child View elements in relative positions
• May be relative to other widgets e.g. android:layout_above or android:layout_toLeftOf a specific widget ID
• May be relative to the parent layout edges (e.g. top, bottom, left, right)
• Some components must be anchored to the layout to provide a concrete basis for anchoring components to each other
– must create reference (@+id/xyz) on first access
• If used carefully can help reduce the need for
nested Layouts/ViewGroups
Semester 1, 2019 COSC2309/2347 Mobile Application Development Topic 3, Slide 19
RelativeLayout.LayoutParams Attributes
XML Attributes (RelativeLayout.LayoutParams)
Attribute Name
Related Method
Description
android:layout_above
N/A
Positions the bottom edge of this view above the given anchor view ID.
android:layout_alignBaseline
N/A
Positions the baseline of this view on the baseline of the given anchor view ID.
android:layout_alignBottom
N/A
Makes the bottom edge of this view match the bottom edge of the given anchor view ID.
android:layout_alignLeft
N/A
Makes the left edge of this view match the left edge of the given anchor view ID.
android:layout_alignParentBottom
N/A
If true, makes the bottom edge of this view match the bottom edge of the parent.
android:layout_alignParentLeft
N/A
If true, makes the left edge of this view match the left edge of the parent.
android:layout_alignParentRight
N/A
If true, makes the right edge of this view match the right edge of the parent.
android:layout_alignParentTop
N/A
If true, makes the top edge of this view match the top edge of the parent.
android:layout_alignRight
N/A
Makes the right edge of this view match the right edge of the given anchor view ID.
android:layout_alignTop
N/A
Makes the top edge of this view match the top edge of the given anchor view ID.
android:layout_alignWithParentIfMissing
N/A
If set to true, the parent will be used as the anchor when the anchor cannot be be found for layout_toLeftOf, layout_toRightOf, etc.
Semester 1, 2019 COSC2309/2347 Mobile Application Development Topic 3, Slide 20
Attributes (contd.)
XML Attributes (RelativeLayout.LayoutParams contd.)
Attribute Name
Related Method
Description
android:layout_below
N/A
Positions the top edge of this view below the given anchor view ID.
android:layout_centerHorizontal
N/A
If true, centers this child horizontally within its parent.
android:layout_centerInParent
N/A
If true, centers this child horizontally and vertically within its parent.
android:layout_centerVertical
N/A
If true, centers this child vertically within its parent.
android:layout_toLeftOf
N/A
Positions the right edge of this view to the left of the given anchor view ID.
android:layout_toRightOf
N/A
Positions the left edge of this view to the right of the given anchor view ID
XML Attributes (RelativeLayout)
Attribute Name
Related Method
Description
android:gravity
setGravity(int)
Specifies how to place the content of an object, both on the x- and y-axis, within the object itself.
android:ignoreGravity
setIgnoreGravity(int)
Indicates what view should not be affected by gravity.
* See API docs for more information
Semester 1, 2019 COSC2309/2347 Mobile Application Development Topic 3, Slide 21
TableLayout
java.lang.Object
↳
android.view.View
↳
android.view.ViewGroup
↳
android.widget.LinearLayout
↳
android.widget.TableLayout
• Organizes children into rows
• Each child is a android.widget.TableRow (with TableRow.LayoutParams) which is
based on a horizontally oriented
LinearLayout
• Each column of each row can be any type of View element
• Columns are based on addition order or explicitly specified using android:layout_column (to skip columns) .. NOTE: 0 indexed
Semester 1, 2019 COSC2309/2347 Mobile Application Development Topic 3, Slide 22
TableLayout Attributes
XML Attributes (TableLayout)
Attribute Name
Related Method
Description
android:collapseColumns
setColumnCollapsed(int,boolean)
The zero-based index of the columns to collapse.
android:shrinkColumns
setShrinkAllColumns(boolean)
The zero-based index of the columns to shrink.
android:stretchColumns
setStretchAllColumns(boolean)
The zero-based index of the columns to stretch.
XML Attributes (TableRow.LayoutParams)
Attribute Name
Related Method
Description
android:layout_column
The index of the column in which this child should be.
android:layout_span
Defines how many columns this child should span.
TableLayout.LayoutParams extends LinearLayout.LayoutParams but does not add any extra attributes (see API for more details)
Semester 1, 2019 COSC2309/2347 Mobile Application Development Topic 3, Slide 23
FrameLayout
java.lang.Object
↳
android.view.View
↳
android.view.ViewGroup
↳
android.widget.FrameLayout
• All activities have a root FrameLayout which holds the content View set by
Activity.setContentView(int
resourceID)
• Displays a stack of child View widgets
• Each View is drawn relative to the top-left
corner of the layout
• The layout is sized to the largest child View in the stack
• Subsequent child Views are drawn on top of previous children (so add larger children first)
Semester 1, 2019 COSC2309/2347 Mobile Application Development Topic 3, Slide 24
FrameLayout Attributes
XML Attributes (FrameLayout)
Attribute Name
Related Method
Description
android:foreground
setForeground(Drawable)
Defines the drawable to draw over the content.
android:foregroundGravity
setForegroundGravity(int)
Defines the gravity to apply to the foreground drawable.
android:measureAllChildren
setMeasureAllChildren(boolean)
Determines whether to measure all children or just those in the VISIBLE or INVISIBLE state when measuring.
XML Attributes (FrameLayout.LayoutParams)
Attribute Name
Related Method
Description
android:layout_gravity
Standard gravity constant that a child can supply to its parent.
* See API docs for more information
Semester 1, 2019 COSC2309/2347 Mobile Application Development Topic 3, Slide 25
TabHost and TabWidget
java.lang.Object
↳
android.view.View
↳
android.view.ViewGroup
↳
android.widget.FrameLayout
↳
android.widget.TabHost
java.lang.Object
↳
android.view.View
↳
android.view.ViewGroup
↳
android.widget.LinearLayout
↳
android.widget.TabWidget
Semester 1, 2019 COSC2309/2347 Mobile Application Development Topic 3, Slide 26
TabHost and TabWidget (contd.)
• TabHost is the root layout in the layout.xml file
• TabHost must contain a TabWidget for the tabs and a FrameLayout for the tab content
– Must be named “@android:id/tabs” and “@android:id/tabcontent” respectively
• These two components can be further organised using other layout components
e.g. LinearLayout
• TabHost originally used with TabActivity (indirectly extends android.app.Activity)
– now deprecated in favour of using Fragments for individual tabs or the AppBar/ActionBar (topic4)
– see both Activity and Fragment approaches in Topic 3 source code
– See https://developer.android.com/reference/android/support/v4/app/FragmentTabHost
• A set of TabHost.TabSpec instances are added to the TabHost to define information about each tab (e.g. text, icon and Activity (via an Intent))
• Generally a separate Activity is used for each tab (for cohesion and modularity) but can use a TabHost.TabContentFactory to generate a separate View for each tab instead
– see TabHost.TabSpec.setContent(Intent) and TabHost.TabSpec.setContent(TabHost.TabContentFactory)
Semester 1, 2019 COSC2309/2347 Mobile Application Development Topic 3, Slide 27
Tab Related Attributes
NOTE: Deprecation warnings now only show in Android Studio if your minSdkVersion is > deprecation level
XML Attributes (TabWidget)
Attribute Name
Related Method
Description
android:divider
Drawable used to draw the divider between tabs.
android:tabStripEnabled
Determines whether the strip under the tab indicators is drawn or not.
android:tabStripLeft
Drawable used to draw the left part of the strip underneath the tabs.
android:tabStripRight
Drawable used to draw the right part of the strip underneath the tabs.
TabHost extends FrameLayout and thus has FrameLayout.LayoutParams but does not add any extra attributes
Semester 1, 2019 COSC2309/2347 Mobile Application Development Topic 3, Slide 28
ConstraintLayout
java.lang.Object
↳ android.view.View
↳ android.view.ViewGroup
↳ android.support.constraint.ConstraintLayout
dependencies {
compile ‘com.android.support.constraint:constraint-layout:1.1.3’
}
• Complex layouts with a flat view hierarchy (i.e. no layout nesting)
• Has the most complete Design View support for drag and drop building
• Is provided as a support library
• See following slide for overview of
• •
features
https://developer.android.com/training/constraint- layout/index.html https://developer.android.com/reference/android/s upport/constraint/ConstraintLayout.html
Semester 1, 2019 COSC2309/2347 Mobile Application Development Topic 3, Slide 29
ConstraintLayout
• Must specify at least one horizontal and one vertical constraint for each view in the layout e.g.
app:layout_constraintLeft_toLeftOf=”parent”
app:layout_constraintRight_toLeftOf=”@+id/seek_edit”
app:layout_constraintTop_toBottomOf=”@+id/desc_text”
• Can be specified relative to the parent or another component in the layout
• Can specify per view margins
• Special usage of 0dp for layout_width or layout_height means
MATCH_CONSTRAINT (i.e. individual view resizes according to constraints
respecting margins)
• Can define minWidth and minHeight for the ConstraintLayout itself
(used to constrain wrap content)
• Can add invisible guidelines to assist layout (views relative to guidelines)
• Can chain views horizontally or vertically to provide linear LinearLayout
like behaviour
Semester 1, 2019 COSC2309/2347 Mobile Application Development Topic 3, Slide 30
GridLayout
java.lang.Object
↳
android.view.View
↳
android.view.ViewGroup
↳
android.widget.GridLayout
• Organizes children into a rectangular grid of cells arranged in rows and columns
– rowCount and columnCount attributes
• supports row and column spanning so
child views can span multiple cells
– layout_rowSpan and layout_columnSpan
• views can be aligned horizontally or vertically
• Views can be placed
– with explicit zero indexed column refs
layout_column and layout_row
– implicitly (see next slide)
• Cell size based on size of largest child view
Semester 1, 2019 COSC2309/2347 Mobile Application Development Topic 3, Slide 31
Automatic Index Allocation
See Topic 3 grid_layout_implicit.xml
FROM: http://android-developers.blogspot.com.au/2011/11/new-layout-widgets-space-and-gridlayout.html
Semester 1, 2019 COSC2309/2347 Mobile Application Development Topic 3, Slide 32
Layouts and compatibility libraries
• As of of Android 9.0 (API level 28) there is a new unified library package called AndroidX
– https://developer.android.com/jetpack/androidx
– You can use either the old or new packages for this course
• Further instructions for configuring non AndroidX support libraries here: https://developer.android.com/topic/libraries/support-library/setup.html
• Main points are full namespace reference in resource files
• add a namespace declaration xmlns:grid=http://schemas.android.com/apk/res-auto
– NOTE: I used grid namespace instead of app for more explicit naming
• use grid: prefix on any GridLayout specific attributes (see res/values/attrs.xml) and grid_layout_2.xml layout example in Topic 3 (which is from the Google API Demos)
Semester 1, 2019 COSC2309/2347 Mobile Application Development Topic 3, Slide 33
Compat. libraries (contd.)
• Add Maven declaration to project Gradle repositories sections:
google()
// for older projects
maven
{
url “https://maven.google.com”
}
• In Android Studio select the “build.gradle (Module: xyz)” file and add this line (in bold) to the dependencies section:
dependencies {
implementation ‘com.android.support:gridlayout-v7:27.1.1’
}
– See https://developer.android.com/topic/libraries/support- library/revisions.html to match your compileSdkVersion version number
• NOTE: Major version number should match compileSdkVersion Semester 1, 2019 COSC2309/2347 Mobile Application Development Topic 3, Slide 34
Compat. libraries (contd.)
• See https://developer.android.com/topic/libraries/support- library/revisions.html
• Android Studio automatically downloads and installs dependencies
– You may need to click a “Sync” link when prompted
– The Android Support Repository and Library (SDK Manager) is no longer
needed
– You can see libraries in Project Structure -> SDK Location then browse the SDK Location for example :
• Once imported check “Project Structure -> Module-> Dependencies” … The library should be “implementation”
Semester 1, 2019 COSC2309/2347 Mobile Application Development Topic 3, Slide 35
Material Design
• In Android 5.0 (API level 21) and above Google introduced a more formal set of UI design/interaction guidelines called Material Design
– https://developer.android.com/guide/topics/ui/look-and-feel Contains a number of related Widgets such as
RecyclerView, CardView
• Other widgets that support material design are provided in the support library (e.g. DrawerLayout, SlidingPaneLayout)
– https://developer.android.com/topic/libraries/support- library/features.html#material-design
– Some widgets like GridLayout exist in core and support libraries
– this practise appears to have been abandoned!
Semester 1, 2019 COSC2309/2347 Mobile Application Development Topic 3, Slide 36
Contexts and Referencing
• The important android.app.Context class was introduced when we discussed Android application Fundamentals
• Activity and Service both extend Context so you often have access to one when you need it
• However sometimes you need to pass a Context to a class such as a Singleton which should not maintain a reference to the Activity/Service since it would interfere with the lifecycle via reference leaking
– Therefore passing ‘this’ from an Activity would be inappropriate!
• Solution: use the application context retrieved from Context.getApplicationContext() which has application lifetime (which is the same as your static singletons)
Semester 1, 2019 COSC2309/2347 Mobile Application Development Topic 3, Slide 37
Obtaining a Context (contd.)
• NOTE: this approach requires us to already have a Context reference from the current Activity/Service
– What if I don’t have one or it would be inconvenient to pass the application context through?
• In this case you can create your own CustomApplication class which extends android.app.Application
• Write as a singleton and override onCreate() wherein you first call super.onCreate() to initialise the Application and then assign ‘this‘ to your static instance which is to be returned from getInstance()
• Finally add a name=”your.app.package.CustomApplication” attribute to the
• Now you can safely retrieve the CustomApplication (which is a Context) from anywhere in your application over the complete application lifetime
Semester 1, 2019 COSC2309/2347 Mobile Application Development Topic 3, Slide 38
// globally get the application Context for non UI classes that need it
public class CustomApplication extends Application {
// declared as actual class type in case we wanted // to add extra methods but not currently used private static CustomApplication application;
@Override
public void onCreate() {
super.onCreate();
// now the CustomApplication (i.e. Application Context) is available application = (CustomApplication) getApplicationContext();
// this should always be true!
if(application != this)
throw new IllegalStateException(“ERROR CREATING APPLICATION CLASS!”);
}
public static CustomApplication getApplication() {
return application; }
}
Semester 1, 2019 COSC2309/2347 Mobile Application Development Topic 3, Slide 39
Lint Warnings and Inspections
• Android Studio uses the lint tools to provide code advice and warnings for both source code and resource files
• See https://developer.android.com/studio/write/lint.html#config
• Sometimes you cannot remove a warning especially when you are
targeting a wide range of release versions (e.g. API 14 through to 27)
• You can suppress with a @SuppressLint(“…”) annotation
• From a command prompt navigate to
• There are also additional “inspections” which you can evaluate and suppress by using the main menu Analyze->Inspect Code… option andresultingInspection ResultstabinAndroidStudio
Semester 1, 2019 COSC2309/2347 Mobile Application Development Topic 3, Slide 40
References
• https://developer.android.com/guide/topics/ui/declaring-layout
• List of resources in android.R.drawable:
https://developer.android.com/reference/android/R.drawable
where ** is ldpi, mdpi etc. to see actual icons etc.
• Online Asset Studio aids in icon creation
https://romannurik.github.io/AndroidAssetStudio/
• Also look at tools on Android device:
– https://developer.android.com/studio/debug/dev-options
– Dev Settings and Dev Tools
– Dev Tools->Package Browser (reads info from manifest)
• Use Android Studio Tools->Layout Inspector as an alternative for debugging layouts
Semester 1, 2019 COSC2309/2347 Mobile Application Development Topic 3, Slide 41