-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainActivity.cs
60 lines (49 loc) · 2.16 KB
/
MainActivity.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using Android.App;
using Android.OS;
using Android.Support.V7.App;
using Android.Runtime;
using Android.Widget;
using Android.Content;
using Android.Content.PM;
using Java.Util;
using Android.Util;
using System;
namespace Android.Localization
{
[Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.Locale)]
public class MainActivity : AppCompatActivity
{
Button btnTranslate;
TextView txtMessage;
Spinner spinner;
Android.Content.Res.Resources res;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.activity_main);
btnTranslate = FindViewById<Button>(Resource.Id.btnTranslate);
txtMessage = FindViewById<TextView>(Resource.Id.textMessage);
spinner = FindViewById<Spinner>(Resource.Id.select_language);
btnTranslate.Click += BtnTranslate_Click;
Context context = this; // Get the Resources object from our context
res = context.Resources; // Get the string
Content.Res.Configuration conf = res.Configuration;
DisplayMetrics dm = res.DisplayMetrics;
conf.SetLocale(new Locale("ak")); //Set local to Akan ak
res.UpdateConfiguration(conf, dm);
var lang = Resources.Configuration.Locale;
var country = lang.GetDisplayCountry(lang);
Toast.MakeText(this, "Your current locale is " + lang, ToastLength.Long).Show();
Toast.MakeText(this, "Country " + country, ToastLength.Long).Show();
Toast.MakeText(this, "Display Name " + lang.DisplayName, ToastLength.Long).Show();
Toast.MakeText(this, "Language " + lang.Language, ToastLength.Long).Show();
}
//
private void BtnTranslate_Click(object sender, System.EventArgs e)
{
string greet = res.GetString(Resource.String.greet_message);
txtMessage.Text = greet;
}
}
}