Text resources that refer to other programs in Android super Simple method _android

Source: Internet
Author: User

It is not uncommon to refer to the text resources of other programs in Android, but it is sometimes necessary to refer mostly to the text resources of the system's programs.

Here's a super simple example to show how to do this.

Copy Code code as follows:

public void testuseandroidstring () {

Context context = GetContext ();
resources res = NULL;
try {
I want to use the Clear_activities string in Package com.android.settings
res = Context.getpackagemanager (). Getresourcesforapplication ("com.android.settings");
int ResourceID = Res.getidentifier ("com.android.settings:string/clear_activities", NULL, NULL);
if (0!= ResourceID) {
Charsequence s = Context.getpackagemanager (). GetText ("Com.android.settings", ResourceID, NULL);
LOG.I (View_log_tag, "resource=" + s);
}
catch (Namenotfoundexception e) {
E.printstacktrace ();
}

}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.