Skip to content
Snippets Groups Projects
Commit 3696e292 authored by fheyming's avatar fheyming
Browse files

Added language selection

parent e06e0fd3
Branches
No related tags found
1 merge request!1Mal aufn Master megren
...@@ -5,6 +5,8 @@ import androidx.fragment.app.FragmentTransaction; ...@@ -5,6 +5,8 @@ import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import android.content.Intent; import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Bundle; import android.os.Bundle;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
...@@ -14,6 +16,7 @@ import android.view.LayoutInflater; ...@@ -14,6 +16,7 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Button; import android.widget.Button;
import android.widget.ImageButton;
import com.example.mampfmobil.R; import com.example.mampfmobil.R;
import com.example.mampfmobil.ui.customer.CustomerLogonFragment; import com.example.mampfmobil.ui.customer.CustomerLogonFragment;
...@@ -23,6 +26,8 @@ import com.example.mampfmobil.ui.deliverer.DelivererRegisterFragment; ...@@ -23,6 +26,8 @@ import com.example.mampfmobil.ui.deliverer.DelivererRegisterFragment;
import com.example.mampfmobil.ui.supplier.SupplierLogonFragment; import com.example.mampfmobil.ui.supplier.SupplierLogonFragment;
import com.example.mampfmobil.ui.supplier.SupplierRegisterFragment; import com.example.mampfmobil.ui.supplier.SupplierRegisterFragment;
import java.util.Locale;
public class DecideFragment extends Fragment { public class DecideFragment extends Fragment {
private DecideViewModel mViewModel; private DecideViewModel mViewModel;
...@@ -36,6 +41,23 @@ public class DecideFragment extends Fragment { ...@@ -36,6 +41,23 @@ public class DecideFragment extends Fragment {
Bundle savedInstanceState) { Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_decide, container, false); View rootView = inflater.inflate(R.layout.fragment_decide, container, false);
ImageButton deButton = rootView.findViewById(R.id.imageView);
ImageButton enButton = rootView.findViewById(R.id.imageView2);
deButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
setLocale("de"); // Aufruf der Funktion zum Ändern der Sprache auf Deutsch
}
});
enButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
setLocale("en"); // Aufruf der Funktion zum Ändern der Sprache auf Englisch
}
});
Button button = rootView.findViewById(R.id.CustomerButton); Button button = rootView.findViewById(R.id.CustomerButton);
button.setOnClickListener(new View.OnClickListener() { button.setOnClickListener(new View.OnClickListener() {
@Override @Override
...@@ -83,4 +105,19 @@ public class DecideFragment extends Fragment { ...@@ -83,4 +105,19 @@ public class DecideFragment extends Fragment {
// TODO: Use the ViewModel // TODO: Use the ViewModel
} }
private void setLocale(String languageCode) {
Locale locale = new Locale(languageCode);
Resources resources = getResources();
Configuration configuration = resources.getConfiguration();
configuration.setLocale(locale);
resources.updateConfiguration(configuration, resources.getDisplayMetrics());
// Hier müssen Sie den Fragments-Wechsel aktualisieren, um sicherzustellen,
// dass die Ansichten und Texte entsprechend der geänderten Sprache aktualisiert werden
FragmentManager fragmentManager = requireActivity().getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.container, new DecideFragment());
fragmentTransaction.commit();
}
} }
\ No newline at end of file
app/src/main/res/drawable/de_flagge.JPG

54.5 KiB

app/src/main/res/drawable/en_flagge.jpg

66.3 KiB

...@@ -45,5 +45,28 @@ ...@@ -45,5 +45,28 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/SupplierButton" app:layout_constraintTop_toBottomOf="@+id/SupplierButton"
app:layout_constraintVertical_bias="0.051" /> app:layout_constraintVertical_bias="0.051" />
<ImageButton
android:id="@+id/imageView"
android:layout_width="100dp"
android:layout_height="60dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="-80dp"
android:src="@drawable/de_flagge"
android:scaleType="fitCenter"
app:layout_constraintEnd_toStartOf="@+id/DelivererButton"
app:layout_constraintTop_toBottomOf="@+id/DelivererButton" />
<ImageButton
android:id="@+id/imageView2"
android:layout_width="100dp"
android:layout_height="60dp"
android:layout_marginStart="-80dp"
android:layout_marginTop="32dp"
android:src="@drawable/en_flagge"
android:scaleType="fitCenter"
app:layout_constraintStart_toEndOf="@+id/DelivererButton"
app:layout_constraintTop_toBottomOf="@+id/DelivererButton" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</FrameLayout> </FrameLayout>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment