7/28/2019 Android Resources
1/18
Development
7/28/2019 Android Resources
2/18
Android
Resources
7/28/2019 Android Resources
3/18
Resources
Ac-vity1
Drawables1 Layout1 Values1
7/28/2019 Android Resources
4/18
Resources
Ac-vity1
Drawables1 Layout1 Values1
Drawables2
7/28/2019 Android Resources
5/18
Resources
Ac-vity1
Drawables1 Layout1 Values1
Drawables2
Layout2 Values2
7/28/2019 Android Resources
6/18
Resources
Ac-vity1
Drawables1 Layout1 Values1
Drawables2
Layout2 Values2
Ac-vity2 Ac-vity3
7/28/2019 Android Resources
7/18
Resources CentralpartofAndroidsflexibilitytochange Resourcefileisbasicallyafileoravaluethatis
boundtoanexecutableapplica-on
Canchangethefileswithoutrecompilingandredeployingtheapplica-on
7/28/2019 Android Resources
8/18
Resources Examples
StringsColorsBitmaps
Insteadofhardcoding,useIDsinstead Letsyouchangecontentwithoutchangingthe
code
7/28/2019 Android Resources
9/18
StringResources
Definemul-plestringsinoneormorexmlresourcesfile
Residein/res/valuessubdirectory Filenameasstrings.xml E.g.
hello
helloappname
7/28/2019 Android Resources
10/18
StringResources
IDEwillmakeuseofaapt(AndroidAssetPackagingTool)toautoma-callycreateor
updateajavaclassinapplica-onrootpackage
CalledR.javawithuniqueIDsfortheresourcesspecified
7/28/2019 Android Resources
11/18
StringResources
Whathappensaerconver-ng? publicfinalclassR
{
publicsta-cfinalclassstring{
publicsta-cfinalinthello=0x7f040000;
publicsta-cfinalintapp_name=0x7f040001;
}
}
7/28/2019 Android Resources
12/18
LayoutResources
Viewofascreen E.g.
setContentView(R.layout.main) Callsoutaconstantcalledmain MainpointstoaviewdefinedbyanXMLlayout
resourcefile
Expectsafiletobecalledmain.xmlinres/layout/. i.e.res/layout/main.xml
7/28/2019 Android Resources
13/18
LayoutResources
7/28/2019 Android Resources
14/18
LayoutResources
Aboveexample,rootnodecalledLinearLayoutwhichcontainsaTextViewfollowedbyabuon
Aseparatelayoutfileforeachscreen ifyouhavetwofilesunder/res/layout/calledfile1.xml
andfile2.xml,youllhavethefollowingentriesinR.java:publicsta-cfinalclasslayout{
publicsta-cfinalintfile1=0x7f030000;
publicsta-cfinalintfile2=0x7f030001;
}
7/28/2019 Android Resources
15/18
ColorResources
Localizecolorsandapplythemes AccesstheminjavacodethroughtheirIDs .R.colornamespace.
7/28/2019 Android Resources
16/18
ResourceReferenceSyntax @+id/text1 @[package:]type/name resourcetypenamespacesavailableinR.java:
R.drawable R.id R.layout R.string R.ar
XMLresourcereferencesyntaxareasfollows: Drawable Id Layout String Ar
Ifpackagenotspecified,itwillbebasedonthelocalresourcesandtheapplica-onlocalR.javapackage
7/28/2019 Android Resources
17/18
Compiled/NonCompiledResource
Sofarallthexmlexamplesarecompiledresources Getscompiledintobinaryformatbeforebecomingpartof
theinstallablepackage
UseAndroidsuppliedXMLreaderstoreadtheXMLnodes NonCompiledresource
Placedinres/raw/directory Getscopiedasistothedevice ExplicitstreambasedAPIstoreadthesefiles
E.g.Audio/videofiles
7/28/2019 Android Resources
18/18
Resourcedirectories
Defaultresources Usedregardlessofthedevice
configura-on
Whennoalterna-veresourcesmatchthecurrentconfigura-on
E.g. Res/layout/
Alternateresources Designedforusewithspecific
configura-on
Appendanappropriateconfigura-onqualifiertothedirectoryname
E.g. Res/layoutland