65+ stand remember position and changes the theme.

This commit is contained in:
sebas
2021-01-05 15:50:29 +01:00
parent 2e5f57aa23
commit 360198e784
3 changed files with 38 additions and 0 deletions

View File

@@ -1,9 +1,11 @@
package com.a1.nextlocation.fragments;
import android.content.SharedPreferences;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.SwitchCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
@@ -20,6 +22,7 @@ import com.a1.nextlocation.R;
public class SettingsFragment extends Fragment {
private ImageView imageButton;
SwitchCompat fontChanger;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -46,6 +49,29 @@ public class SettingsFragment extends Fragment {
((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, homeFragment).addToBackStack(null).commit();
});
fontChanger = view.findViewById(R.id.BigFont);
SharedPreferences sharedPreferences = requireActivity().getSharedPreferences("com.a1.nextlocation",0);
final SharedPreferences.Editor editor = sharedPreferences.edit();
fontChanger.setChecked(sharedPreferences.getBoolean("switch",false));
fontChanger.setOnClickListener(view1 -> {
if(fontChanger.isChecked())
{
requireActivity().setTheme(R.style.Theme_NextLocationBig);
editor.putBoolean("switch",true);
editor.apply();
}
if(!fontChanger.isChecked())
{
requireActivity().setTheme(R.style.Theme_NextLocation);
editor.putBoolean("switch",false);
editor.apply();
}
editor.commit();
});
String[] items = new String[]{"Nederlands", "Engels", "Chinees"};
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_dropdown_item, items);

View File

@@ -160,6 +160,7 @@
<androidx.appcompat.widget.SwitchCompat
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/BigFont"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@id/Balk3"

View File

@@ -7,5 +7,16 @@
<item name="colorSecondary">@color/secondaryColour</item>
<!-- Customize your theme here. -->
<item name="colorButtonNormal">@color/buttonColour</item>
<item name="android:textSize">16sp</item>
</style>
<style name="Theme.NextLocationBig" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/primaryColour</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/secondaryColour</item>
<!-- Customize your theme here. -->
<item name="colorButtonNormal">@color/buttonColour</item>
<item name="android:textSize">24sp</item>
</style>
</resources>