Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the language of the Calendar View?

Tags:

I used View Calendar Spanish but I am not sure how to change the language, there is some property that is not available anywhere.

Now I have this:

enter image description here

<CalendarView
android:id="@+id/calendari"
android:layout_margin="10dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weekNumberColor="@color/botoCalendari"
    android:focusedMonthDateColor="#d91f1f"
    android:weekSeparatorLineColor="#1fd928"
    android:selectedWeekBackgroundColor="#1fd9d6"
    android:unfocusedMonthDateColor="#d91fd9"

    />

Is there any property or by code ?

Thank you very much.

like image 463
Laura Avatar asked May 17 '16 11:05

Laura


2 Answers

This may helps you.

import android.app.Activity;
import android.content.res.Configuration;
import android.os.Bundle;

public class Main extends Activity {
 /** Called when the activity is first created. */
 @Override
  public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

String languageToLoad  = "fa"; // your language
Locale locale = new Locale(languageToLoad); 
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config, 
  getBaseContext().getResources().getDisplayMetrics());
this.setContentView(R.layout.main);
}
}

you find example here

like image 170
Sathish Kumar J Avatar answered Sep 28 '22 02:09

Sathish Kumar J


Nope. CalendarView doesn't have such a property. The language used in the view is the default device's language.

You can try to change the locale dynamically when starting your application.

Example:

Locale locale = new Locale("en_US"); 
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
context.getApplicationContext().getResources().updateConfiguration(config, null);
like image 36
Seishin Avatar answered Sep 28 '22 02:09

Seishin