Android extract string resource from layout xml file

不打扰是莪最后的温柔 提交于 2019-12-07 12:12:12

问题


I try to extract hardcoded strings from xml file but always got an error. Select hardcoded text, ctrl+1 , extract android string and this error pops instead of Android Extract String pop-up.

"The attribute android:text does not accept a string reference"...

Why do i get this error any tips?

I work with eclipse 3.7.1 and adt v16, operating system windows 7.

This is the error

Added video that shows the feature http://www.youtube.com/watch?feature=player_embedded&v=Oq05KqjXTvs#t=1881s


回答1:


I just found how to activate this feature.

Simply press "crtl+1" and the menu will pop out.

I was searching for this feature too until i found your post....

Thank you for the video too.




回答2:


I am not really sure what you are trying to do but i'd like to give you some tips and I hope that this is going to answer your question.

First you should write any Strings which do not change at runtime in your project/res/value/strings.xml

An strings.xml entry example:

    <string name="text_button">Any Text</string>

Now you can access this string in your XML like that:

    android:text="@string/text_button" />

However, you'd like to access this string at runtime? Then try this:

TextView tv_1 = (TextView) findViewById(R.id.text1);
String myText = tv_1.getText();

And read this: http://developer.android.com/guide/topics/resources/accessing-resources.html



来源:https://stackoverflow.com/questions/9302636/android-extract-string-resource-from-layout-xml-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!