Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Language while using Navigation Component API 24+

TL;DR We want to change the locale (API 24+) for a to be displayed fragments while all these fragments are going to be inside the same activity.

We are using NavHostFragment, and start_up_nav_graph.xml. This graph has multiple fragments i.e. Log-in, Onboarding, GDPR ..etc

In this flow, If after logging in we find that you are a German user, we try to change your locale to German. In the current scenario, all the up-coming fragments (such as onboarding and GDPR) are going to be displayed in the device's locale, not German.

We can't use attachBaseContext in the activity like this answer, because the activity has already been created.

like image 647
john-salib Avatar asked Aug 09 '19 08:08

john-salib


1 Answers

I'm experiencing same pain brother. i tried to do

NavigationUI.setupWithNavController(mToolbar,mNavController, mAppBarConfiguration);

but this is also not helping because Toolbar Title and Navigation Drawer items are using old resources and when i'm doing activity.recreate() then it's actually happening but when you close app and restart it again same problem...

like image 116
Bunty Petiwala Avatar answered Nov 15 '22 06:11

Bunty Petiwala