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 > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to use Android system resources". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's ideas to study and learn "how to use Android system resources".
1) using system-defined id
For example, we have a xml file that defines ListView. Normally, we will write code snippets similar to the following.
Here we define a ListView whose id is "@ + id/mylist". In fact, if there are no special requirements, you can take advantage of the system-defined id, similar to the following.
To reference the system's id in the xml file, you only need to prefix "@ android:". If you are using system resources in Java code, it is basically the same as using your own resources. The difference is that you need to use the android.R class to use the system's resources instead of using the R class specified by the application. Here, if you want to get the ListView, you can use android.R.id.list to get it.
2) use the picture resources of the system
Suppose we define a menu,xml file in our application as follows.
The code snippet android:icon= "@ android:drawable/ic_menu_attachment" is intended to refer to the "attachment" icon in the existing Menu in the system. But after the Build project, an error was found. The prompts are as follows:
Error: Error: Resource is not public. (at 'icon' with value' @ android:drawable/ic_menu_attachment')
You can probably see from the error message that because the resource is not exposed, it cannot be directly referenced in our application. In that case, we can find the corresponding image resources in Android SDK, copy them directly to our project directory, and then use code snippets like android:icon= "@ drawable/ic_menu_attachment" to reference them.
One of the advantages of this is that artists do not have to repeat an existing picture, which can save a lot of man-hours; the other is to ensure that the style of our application is consistent with the system.
Experience sharing:
There are no exposed resources in Android, and direct references in xml will report an error. In addition to finding the corresponding resources and copying them to our own application directory, we can also change the reference "@ android" to "@ * android". For example, the attachment icon referenced above can be modified to the following code.
Android:icon= "@ * android:drawable/ic_menu_attachment"
After the revision, if you Build the project again, you will not make a mistake.
3) use the string resources of the system
Suppose we want to implement a Dialog,Dialog with "OK" and "cancel" buttons. You can use the following code to directly use the string that comes with the Android system.
If you use the system's strings, multi-locales are already supported by default. As in the above code, @ android:string/yes and @ android:string/no are directly used, "OK" and "cancel" are displayed in simplified Chinese environment, and "OK" and "Cancel" are displayed in English environment.
4) use the Style of the system
Suppose there is a TextView in the layout file that displays the title of the window in a medium-sized font. You can use the following code snippet to define the Style of TextView.
Where android:textAppearance= "? android:attr/textAppearanceMedium" is the style that uses the system. It is important to note that to use the system's style, you need to prefix the resource you want to use with "? android:" instead of "@ android:".
5) using the color definition of the system
In addition to the various system resources mentioned above, you can also use system-defined colors. The most commonly used in projects is the use of transparent colors. The code snippet is as follows.
Android:background = "@ android:color/transparent"
Experience sharing:
The Android system itself has a lot of resources that can be used directly in the application. Specifically, you can check it in the corresponding folder of android-sdk. For example, you can enter $android-sdk$\ platforms\ android-8\ data\ res, and you will have a clear view of the system resources.
Developers need to take some time to familiarize themselves with these resources, especially picture resources and various Style resources, so that in the development process, they can think of relevant resources and use them directly.
Thank you for your reading, the above is the content of "how to use Android system resources", after the study of this article, I believe you have a deeper understanding of how to use Android system resources, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.