Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set android:text from strings.xml

Tags:

android

xml

I am developing two languages program, so I am trying to set some text from res/values-en/strings.xml but I don't have any idea how to do it

from here

<string name="advices">Advices</string>

to here

<TextView
        android:text="TO HERE <---------"
        android:textColor="#999999"
        android:textStyle="bold"
        android:textSize="12sp" />
like image 963
Jacek Grzelaczyk Avatar asked Aug 29 '13 07:08

Jacek Grzelaczyk


People also ask

What is the use of String xml file in Android?

A string resource provides text strings for your application with optional text styling and formatting. There are three types of resources that can provide your application with strings: String. XML resource that provides a single string.

How do you put and in String?

The reference to entity "Drop" must end with the ';' delimiter. How can I write character & in the strings. xml? In android studio, you can simply press Alt+Enter and it will convert for you.

What is String in xml?

A string is a simple resource that is referenced using the value provided in the name attribute (not the name of the XML file). So, you can combine string resources with other simple resources in the one XML file, under one <resources> element.


2 Answers

You can get text from strings by using @string keyword.

<TextView
        android:text="@string/advices"
        android:textColor="#999999"
        android:textStyle="bold"
        android:textSize="12sp" />

and there is an another way to do this :

->> Right click on the TextView on which you want to set text from strings. Select EditText from the menu or alternatively you can press F2 Function Key

right click on text view

->> Now all strings will be listed which are available in your strings.xml. Select the required string from list.

select edit text

->> Now you can see your string in your text view.

text in text view

like image 109
2 revs Avatar answered Oct 07 '22 13:10

2 revs


First of all in your res folder, there will be values named folder in which you will have strings.xml file.In that file you have to put your all English String in it.

And now if you want to use another language like Spanish then make values-es named folder and put all Spanish meaning for English Language..

and set something like this:

<TextView
    android:textColor="#999999"
    android:textStyle="bold"
    android:text="@string/string_here"
    android:textSize="12sp" />
like image 24
Piyush Avatar answered Oct 07 '22 13:10

Piyush