更换(或QUOT;越权QUOT;)字符串中的Andr​​oid库项目 [英] Replace (or "Override") String in Android Library Project

查看:169
本文介绍了更换(或QUOT;越权QUOT;)字符串中的Andr​​oid库项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图让一个Android库项目,并同时生成过程中正常工作,我一直在运行与在使用该库的项目替换的资源一定的麻烦。

I've been trying to make an android library project, and while the build process works fine, I've been running into some trouble with replacing a resource in the project which uses the library.

在我的图书馆我有:

  1. A library_layout.xml 包含

< TextView的
    机器人:ID =@ + ID / str_my_string
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_text =WRAP_CONTENT
    >

<TextView
android:id="@+id/str_my_string"
android:layout_width="wrap_content"
android:layout_text="wrap_content"
>

它调用Java文件

((TextView中)this.findViewById(R.id.str_my_string))的setText(R.string.my_string);

((TextView)this.findViewById(R.id.str_my_string)).setText(R.string.my_string);

一个资源的strings.xml 包含

&LT;字符串名称=my_string&GT;占位符&LT; /串&GT;

<string name="my_string">Placeholder</string>

在项目中使用的图书馆中,我有

In the project using the library I have

  1. 一个资源的strings.xml 包含

&LT;字符串名称=my_string&GT;实际字符串含量小于/串&GT;

<string name="my_string">Actual string content</string>

我期望的行为是,当我使用该库运行项目,文本视图显示实际字符串内容,但它实际上包含的错误

The behavior I expect is that when I run the project using the library, the text view displays Actual string content, but it actually contains false.

展望中使用该库的应用程序,我的执行的看到两个研究文件,并且都具有 R.string.my_string 和这两个都等于相同的数值。

Looking in the app which uses the library, I do see two R files, and both of them have R.string.my_string and both of those are equal to the same numeric value.

推荐答案

我有同样的安排,这对我的作品如预期。

I have the same arrangement and this works for me as expected.

图书馆有布局/类此引用字符串资源:

The library has layout/class with this reference to a string resources:

<TextView android:id="@+id/studentSinceLabel">

该库提供了在其strings.xml中的默认值:

The library provides a default value in its strings.xml:

<string name="studentSinceLabel">Student Since</string>

主要应用在它的strings.xml这个值:

The main app has this value in its strings.xml:

<string name="studentSinceLabel">Client Since</string>

当我givve在主应用程序的strings.xml此资源的值,我看客户端自时,应用程序运行时,当我从主应用程序的strings.xml删除它,我看从图书馆的价值, 学生从

When I givve a value for this resource in the main apps strings.xml, I see "Client Since" when the app runs, when I delete it from the main apps strings.xml, I see the value from the library, "Student Since".

似乎这种预期基于我在这里的阅读行为: <一href="http://developer.android.com/tools/sdk/eclipse-adt.html">http://developer.android.com/tools/sdk/eclipse-adt.html

Seems this is expected behavior based on my reading here: http://developer.android.com/tools/sdk/eclipse-adt.html

从上面的链接的相关报价:

Relevant quote from link above:

在其中资源ID在应用程序和库定义的情况下,该工具可确保在应用程序中声明的资源获得优先权,并在库项目的资源没有编译到应用程序.apk文件。这使您的应用程序的灵活性,或者使用或者重新定义在任何库中定义的任何资源行为或值。

In the cases where a resource ID is defined in both the application and the library, the tools ensure that the resource declared in the application gets priority and that the resource in the library project is not compiled into the application .apk. This gives your application the flexibility to either use or redefine any resource behaviors or values that are defined in any library.

这篇关于更换(或QUOT;越权QUOT;)字符串中的Andr​​oid库项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆