Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get default strings on Android (DatePickerDialog title etc.)

Tags:

android

I just created my own custom TimePickerDialog (implemented skipping and other things) and I'm wondering how I can use the same title as in the original TimePickerDialog "Select date". I could hardcode it, as the people downloading this app will only be norwegian, but it will be inconsistent for users with english language set in their phones (the DatePicker has english text, the TimePicker has norwegian...).

I looked at android.R.strings, but i could only find very basic strings like "cancel", "yes", "no" etc... is there anyway to get the default localized title for DateDialog, or other dialogs for that matter?

like image 697
Robin Heggelund Hansen Avatar asked Nov 30 '22 06:11

Robin Heggelund Hansen


2 Answers

There are some default strings available in android.R.string. You can get them like this:

String no = yourContext.getString(android.R.string.no);
like image 51
Kirill Rakhman Avatar answered Dec 05 '22 00:12

Kirill Rakhman


You need to define your own values in a strings.xml file (doc: http://developer.android.com/guide/topics/resources/string-resource.html).

For example, you could declare in res/values/strings.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="select_date">Select Date</string>
</resources>

Then, in your layout, you need to use this value via @string/select_date

If you want your app to support several languages, you have to add additionnal strings.xml files that will be located in res/values-[the language]/strings.xml

So for example, in order to support french, you would have in res/values-fr/strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="select_date">Choisissez une date</string>
</resources>
like image 30
Anordil Avatar answered Dec 05 '22 02:12

Anordil