I have one ques that whether it is开发者_Python百科 good to give all string text that we are going to use in our layout file in strings.xml file or should we give it in "string text" in layout file itself for attribute values like android:text="some text"
.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:id="@+id/ll1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button android:text="Button"
android:id="@+id/butShow"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</Button>
</LinearLayout>
then is it fine to give android:text="Button"
or we should use android:text="@string/btnlabel"
strings.xml
<resources>
<string name="btnLabel">Button</string>
</resources>
We should specify all string text in strings.xml or only specific ones.
check my answer hereOk
After looking into the source code of android.content.res.resources and some other classes, it is evident that using Resources and getting resources through getResources()
is a bit costly.
However, using getResources() has its advantages:
- It helps you externalize your resources.
For any type of resource, you can specify default and multiple alternative resources depending maybe on Locale, Screen Depth/Resolution...
You will do better to extract all your strings to strings.xml incase you ever decide to internationalize your app! then you only have to do a different strings.xml for each language rather than layouts too
精彩评论