Hey there.
Well now let's learn how to use the preference fragment in all application.
We will use the new preference fragment compact version and therefore we need to use the Android support
library app compote.
Let's enter Android support library
go to the developers website and then we need to enable the research one version of the support library
to do this.
We need to put this dependency in the bill rather file select build grow the model app
and add one more dependency implementation and then paste it into this file and then we synchronize
the project.
Now let's create a new class in our package new Joe class and call it settings fragment
and extends from reference fragment compote
so why something displayed in Red let's try to rebuild the project and we get an error it's instead
of come compote add preference dependency and let's try to synchronize and now the building is completed
successfully and added a class from there.
This one reference library and now we have our class underlined with the red line and it is written
about that we need to either declare this abstract or implement the abstract method on create preferences.
Of course we implement that we will implement this method click here implement methods.
Here is just this one method that we need to implement.
Let me call ups this step and now that we have this fragment let's create an excel file that will display
the layout of these fragment.
Let's create a new folder in the race folder new directory and name it.
Email.
And here we will be our all out file.
Right.
Colleague new resource file and call it for example time preferences timer settings gay
and our simple file is created.
And as you can see here the external tank the scope reference screen.
And in these external uh we can.
Now our own of different settings checkboxes text fields and others that is group them on the Settings
screen.
Let's add our first setting.
Let it be checkbox preference polls.
The tag
by checking the books in this checkbooks.
For example we can mute the salt of our time.
Let us have a Thatcher an adjustment settings here inside.
We will set the attribute of these checkbooks.
Here we will first specify the default value for these checkbooks and specify true that is we will have
a sound in our time is turned on by default.
Next we indicate the attribute key and we specify a value for example enable sound
which means salt is a load and so on.
This key can be found.
The value of the settings the sound is turned on or off the value.
The next value title is the title of this setting.
We can also call it enables sound and then there are such properties.
A summary of and summary own.
This is the text that will be displayed in the setting when these checkbooks is turned on or off.
That is there is a check mark or not.
That is when there is no check mark.
The text indicated by summary.
Or for example this text sound is a sound is not available and when there is a checkmark sound enabled
will display will be displayed.
This text and the way we created the exam allowed for sitting.
Let's go back to our settings fragment and inside the own create preferences method.
We will call the ad preference preferences from resource method and indicate here our timer preferences.
For that we just created it is specified in this way or that some time our preferences and this call
will create a setting from this file.
And now we need to add this fragment that we just created to our settings activity to do this.
We need to find the layout of our settings activity.
This is the activity settings ex email file and replace here instead of constraint cloud.
We will specify fragment.
Next we remove these attributes.
And this also.
Next we specify the I.D. of our fragment.
Let it be also activity settings named
and will specify the name attribute in which we will specify the name of our class settings fragment
and the last drop that we need to add is go to the values folder styles file and add a theme for our
fragment item name preference theme.
And here we specify style
slash preference theme overlay.
Well now it's time to check if our code is working.
The launch of the application
lets open all our menu click settings
and as you can see the checkbox setting appears and it saves time to enable salt and summary.
Oh no salt.
Enable.
If we turn it off then sound desirable is displayed in summer.
Oh cool we did it.