In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the relevant knowledge of "how to use android resource files". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
For android beginners, the first thing is to understand the type and layout of resource files, and then the use of resource files. The list of resources is as follows:
The use of a resource file is divided into using it in code and referencing it in other resource files. When we compile an Android application, Android will automatically generate an R class, which generates a corresponding internal class according to different resource types, which contains the markings of all the resource files used in the system, as shown below.
Package com.amaker.mp
/ / Resource class
Public final class R {
/ / array
Public static final class array {
Public static final int faultRecords=0x7f060000
}
/ / attribute
Public static final class attr {
}
/ / Color
Public static final class color {
Public static final int black=0x7f040001
Public static final int red=0x7f040000
}
/ / Picture
Public static final class drawable {
Public static final int icon=0x7f020001
Public static final int logo2=0x7f020002
}
/ / ID marking
Public static final class id {
Public static final int licenseEditText=0x7f070022
Public static final int lngEditText=0x7f070001
}
/ / layout
Public static final class layout {
Public static final int custom_dialog=0x7f030000
Public static final int custom_dialog1=0x7f030001
}
/ / string
Public static final class string {
Public static final int app_name=0x7f050001
Public static final int hello=0x7f050000;}}
1. Use the resource file in the code to access the resource file in the code, by using the resource file type and resource file name defined in the R resource class. The specific format is: R. Resource file type. Resource file name. For example:
/ / set the layout view displayed by Activity
SetContentView (R.layout.login_system)
/ / obtain Button instance
CancelBtn = (Button) findViewById (R.id.cancelButton)
LoginBtn = (Button) findViewById (R.id.loginButton)
/ / obtain TextView instance
UserEditText = (EditText) findViewById (R.id.userEditText)
PwdEditText = (EditText) findViewById (R.id.pwdEditText)
}
In addition, in addition to accessing the user-defined resource files, you can also access the resource files in the system. Most of the resource files are defined in the R class under the android package. The format of the resource file in the access system is: android.R. Resource file type. Resource file name. For example:
Int i
/ / Animation
I = android.R.anim.fade_in
/ / array
I = android.R.array.emailAddressTypes
/ / Color
I = android.R.color.darker_gray
/ / Dimension
I = android.R.dimen.app_icon_size
/ / Pictures can be drawn
I = android.R.drawable.title_bar
/ / string
I = android.R.string.cancel
two。 Reference resource files in other resource files
We often refer to other resource files in the element attributes of layout files, such as strings, pictures, colors, and so on. For example, the TextView component in the following layout file references a string to represent the text content, a color to represent the text color, and a size to represent the text size.
This is the end of the content of "how to use android Resource Files". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.