How to put a theme on your Android phone

How to enable dark mode (theme, design) on your Android phone

Good time!

Have you heard of the fact that a dark theme can somewhat extend the life of your battery reduce the strain on your eyes (especially if you often use the phone at night)?! #x1f440;

Perhaps that’s why, recently, many developers are starting to introduce night and dark modes into their software. This applies to both Windows and Android.

I wanted to show you how you can easily activate the mode (and reduce the bright white screen light).

Note: this note is universal and should fit to phones of different brands: Samsung, LG, Redmi, etc. Nevertheless, in some cases, I do not exclude the appearance of unpleasant “features”. (for example, on devices from Sony it is not always possible to use a third-party application to change the background. )

How to change the theme on Honor and personalize your phone

How to change the theme on Honor? Go to the “Themes” application on your smartphone desktop, click on the “Categories” button and select the appropriate section, for example, “Top free”. Find the right theme, enter it, and click “Free Download”. After completing the process, click “Apply”. The same principle can be used to install the paid options, as well as the black option. Below we will look at how to change the theme, create a new one or properly update an existing one.

There are three ways to install and change a new theme on the Android operating system:

  • Go to Google Play.
  • In the search line, enter: “theme”.
  • Select the theme you like.
  • Press “Install”.

The advantage of this method is that it is very simple, but the disadvantage is that most of the themes in Goggle Play are paid.

  • Set the theme via a synchronization program with your computer. Themes are installed in the same way as applications, for this you can use any program for synchronization with the function of installing applications.

In MyPhoneExplorer, click on “Applications” in the “Files” menu, then click on the “Install” button. Select a theme file (with an extension.APK), then on your device to confirm the installation.

  • you need a computer at your fingertips
  • requires the installation of a synchronizer program
  • Use AppsInstaller. This is a program that allows you to install applications on your Android device directly from its memory.
  • Download and install AppsInstaller on your device.
  • Copy the.APK file into the memory of your device (it does not matter if it is on the internal memory or on the SD card).
  • Run AppsInstaller, the program will search the memory of your device for files with the required extension and display their list.
  • Select the theme you want.

All of these methods are available to the average user.

How to install a theme on Android via Google Play

You can install the theme either directly from your mobile device or remotely from your Google account on your computer. Both variants are almost identical.

you need to enter the play page.Google.com. Normally it is in English, but it is easy enough to fix this by selecting your language at the bottom of the page.

In the search box that opens, you must enter the word theme (theme), resulting in a huge variety of different options will appear. After selecting one of them you need to press the Install button. The only thing you need for this is a Google Play account. In addition, many themes there are paid.

Themes for Android devices are the same applications, which means that they are installed using special programs.

Having installed such a synchronization program on your PC (most often supplied with the Android device), you can install a new theme on your desktop.

To begin with, in such an application it is necessary in the “Settings” window to open access to unknown sources (the corresponding column is present there). The phone is connected to the computer with a USB cord.

Most often the required program is called “Application Installer”. When you run it, the program prompts you to specify the location of the necessary file. By specifying it and confirming your action, you can install.

How to install a theme on your Android phone

Every Android owner eventually gets bored with the look of his device’s workspace, and he wants to change something. The installation of new wallpaper is already boring, and you want some more dramatic changes. We can change the theme on our smartphone. (By the way, they’re also called skins, so later in the text will sometimes apply this word.) Let’s figure out how to install a theme on Android.

Themes and Styles in Android Without Magic. And how to prepare them with SwitchCompat

In the previous article we looked at how to use themes and styles at code level, using a custom view as an example. In this article let’s look at several ways of styling a standard ui element, particularly SwitchCompat.

Introduction

Not always the default design of the standard UI element suits the designer. Let’s break down how to change the appearance of an element using the SwitchCompat example.

  • Specify for each view in the layout screens through the style attribute.
  • Create a theme with the overridden switchStyle attribute and assign this theme to the manifest for the entire application or a specific activity. This changes the appearance of the entire application/activity.
  • The theme can also be set programmatically in the activation code. You can change it on the fly if needed.
Read more:  How to Add Music to Android

New style for SwitchCompat

Create a new style MySwitchStyle in the resources, inherit the design from the Widget.AppCompat.compoundButton.Switch, by specifying the parent. You can also choose not to inherit, but then you have to specify all the values, even the ones you don’t plan to change.

To change something, you need to override the required attributes. You can look up attributes in documentation.

In the documentation, we see several attributes. They are specified as if we refer to them in code (for example, like this R.styleable.SwitchCompat_android_thumb). I will decipher only part of them, so that there is no doubt. The purpose of the others is easy to understand from the documentation.

theme, your, android, phone
In the code In the xml
SwitchCompat_android_thumb Android:thumb
SwitchCompat_thumbTint thumbTint
SwitchCompat_track track
SwitchCompat_trackTint trackTint
  • android:thumb is the resource for the moving part of the SwitchCompat
  • track is a resource for the static part of SwitchCompat
  • thumbTint. allows us to color the moving part in the right colors, depending on the state of SwitchCompat
  • trackTint. allows you to color the fixed part with the right colors depending on the state of the SwitchCompat

We need a selector in the color folder of our resources. The file selector_switch_thumb.xml

Now let’s set the thumbTint attribute in our style.

Now all SwitchCompats that somehow got the MySwitchStyle style will look new.

Style in the layout

  • The style is applied when the layout resource.
  • There is no way of influencing this programmatically.
  • Specifying every time in the layout is inconvenient. And we can forget.

make your android homescreen aesthetic �� pastel purple theme ��

Style in theme. Theme is assigned through Manifest

Create an AppTheme and set the switchStyle attribute. The value is our MySwitchStyle.

The theme can be specified in the manifest for the entire application

All SwitchCompats will now have a new look and feel. No change to the layout.

Style in theme. The theme is assigned programmatically

To set the theme for an activity programmatically, you need to call the activity’s setTheme(themeResId) method.

Let’s change the theme of the activiti depending on the state of Switch.

  • Set the theme programmatically by calling setTheme. The method must be called before super.onCreate(savedInstanceState). In onCreate we have the initialization of the snippets (when we have them).
  • Setting the initial state of Switch, depending on the theme.
  • Set a listener that changes the theme in the settings and restarts the activiti via the activiti recreate method.

Other View

To redefine a style for SwitShView for the whole application, we redefined the value of the switchStyle attribute, you can guess that there are such attributes for other View.

A snippet from the Base Theme.V7.Theme.AppCompat.Light.

Resources

This article does not claim to be a complete guide. Code is intentionally abridged. I set the task to give a general understanding of how it works and why it’s needed. You can easily find the rest in the documentation and standard resources.

Themes and styles in Android apps

Every Android developer has had to work with styles at one time or another. Some of them feel confident about them, while others have only superficial knowledge that often does not allow them to solve the task at hand.

In anticipation of the release of the dark theme, it was decided to refresh my memory on all the information concerning themes and styles in Android applications.

What we’re going to talk about:

  • Let’s look at the basic concepts of themes and styles in Android applications and see what features they give us;
  • Let’s create a simple theme using Material Components and play with style overrides;
  • Let’s understand how a dark theme works;
  • Formulate recommendations for working with styles.

Let’s start with the basics

Themes and styles have a common structure:

The tag style is used to create. Each style has a name and stores key-value parameters.

It’s pretty simple. But what is the difference between a theme and a style??

The only difference is how we use them.

A theme is a set of parameters that apply to an entire application, Activity, or View component. It contains the basic colors of the application, the styles for rendering all the components of the application, and various settings.

The theme redefines the colors of your application ( colorPrimary. colorSecondary ), a style for text ( textAppearanceHeadline1 ) and some standard components of the app, and a parameter for the transparent status bar.

In order for a style to become a real theme, it’s necessary to inherit (we’ll talk about inheritance later) from the default implementation of the theme.

Style

A style is a set of parameters for styling a single View component.

The attribute

The attribute is usually called a style or theme key. These are the little bricks from which everything is built:

All of these keys are standard attributes.

The myFavoriteColor attribute will point to a color or reference to a color resource.

In the format, we can specify quite standard values:

  • color
  • reference
  • string
  • enum
  • fraction
  • dimension
  • boolean
  • flags
  • float
  • integer

By its nature, the attribute is an interface. It must be implemented in the theme:

Now we can refer to it. The general structure of the reference looks like this:

And finally, let’s change, for example, the color of the text in a field:

Thanks to attributes, we can add whatever abstractions we want that will change within the theme.

Inheriting Themes and Styles

As in OOP, we can inherit the functionality of an existing implementation. You can do this in two ways:

With explicit inheritance we specify the parent using the parent keyword :

With implicit inheritance, we use a dot-notation to specify the parent:

There is no difference in how these approaches work.

theme, your, android, phone

Very often we can come across such styles:

It would seem that a style is created by double inheritance. This is not really the case. Multiple inheritance is forbidden. In this definition, explicit inheritance always wins.

That is, a style named Widget will be created.MyApp.Snackbar. The Widget, which is a descendant of the Widget.MaterialComponents.Snackbar.

ThemeOverlay

ThemeOverlay are special “lightweight” themes that allow you to override the attributes of the main theme for a View component.

We won’t go far to find an example, but take the case of our application. The designers decided that we need to make a standard login box that has a different color from the main style.

With the main theme, the input box looks like this:

It looks great, but the designers insist that the box should be in brown.

Write your own view according to the guideline and with custom parameters?

The right solution is to use ThemeOverlay.

Create a ThemeOverlay and redefine the main color of the theme:

Then we specify it using the special tag Android:theme in our TextInputLayout :

Of course the question arises. how does this work under the hood?

ContextThemeWrapper allows us to do this magic. When you create a View in LayoutInflater, a context will be created where the current theme will be taken as the basis and it will override the parameters that we specified in our Overlay theme.

Read more:  How To Add A Contact To The Blacklist On Android

In the same way we can redefine any parameter of the theme.

Sequence of applying themes and styles to a View component

The main priority is the markup file. If a parameter is defined in it, then all similar parameters will be ignored.

Next, the predefined styles for the component are used:

If no parameters were found, theme attributes are used:

That’s basically all you need to know to start working with themes. Now let’s have a quick look at the updated Material Components design library.

May Material Components be with us

Material Components was introduced at Google I/O 2018 and is a replacement for the Design Support Library.

The library gives us the opportunity to use the updated components from Material Design 2.0. In addition, it has a lot of interesting customization options. All this allows you to write outstanding and unique applications.

Here are some examples of apps in the new style: Owl, Reply, Crane.

Let’s move on to practice

To create a theme, you need to inherit from a base theme:

They are all very similar to AppCompat themes, but have additional attributes and settings.

You can learn more about the new attributes at material.io.

If for some reason you can’t switch to a new theme right now, the Bridge themes will work for you. They are inherited from AppCompat themes and have all the new attributes of Material Components. All you need to do is add the Bridge postfix and use all the features without fear:

The names of the primary colors (brand colors) have changed:

information on colors can be found at material.io.

I already mentioned that the theme contains standard styles for each View component. For example, for Snackbar, the style will be called snackbarStyle. for checkbox. checkboxStyle and then everything is similar. An example will put everything in its place:

Let’s create our own style and apply it to the theme:

It’s important to understand that when you override a style in a theme, it will apply to all View of that type in the application (Activity).

If you want to apply a style to only one particular View, you need to use the style tag in the layout file:

One of the innovations that really impressed me is ShapeAppearance. It allows you to change the shape of components right in the theme!

Each View component belongs to a specific group:

shapeAppearanceSmallComponent

shapeAppearanceMediumComponent

shapeAppearanceLargeComponent

As we can understand from the name, there are different sizes of views in the groups.

We created a Widget.MyApp.SmallShapeAppearance for “small” components. Rounded the top left corner by 20dp and cut the bottom right corner by 15dp.

Looks interesting. Would this work in real life? Time will tell.

As with styles, we can only apply ShapeAppearance to a single View component.

What’s up with the dark theme?

Very soon will be released Android Q, and with it the official dark theme will come to us.

theme, your, android, phone

Perhaps one of the most interesting and spectacular features of the new Android version is the automatic application of a dark theme for the whole application with one line of code.

Sounds great, let’s try it out. I propose to take everyone’s favorite gitlab client from terrakok.

Allow you to repaint the app (prohibited by default):

The Android:forceDarkAllowed attribute is available from API 29 (Android Q).

Agree that for one line of code it looks very cool.

Of course, there are some problems. BottomNavigationBar merges with the background, lowader stays white, code highlighting suffers, and that’s about it, at least nothing else serious caught my eye.

I’m sure that by spending not much time you can solve the main problems. For example, by disabling the automatic dark mode for individual views (yes, you can do that too. Android:forceDarkAllowed is available for View in the markup file).

Remember that this mode is only available for light themes, if you use a dark theme, then the forced dark theme will not work.

You can read the guidelines in the documentation and on the.io.

And if we want to do everything ourselves?

As simple as it is to use a forced dark theme, this mode lacks flexibility. In fact, everything works according to predefined rules, which may not suit us and, more importantly, the customer. I think that this solution can be seen as a temporary one, until we make our own implementation of the dark theme.

In API 8 (Froyo), a qualifier was added.night. which is still used to this day to apply the dark theme. It allows you to automatically apply the right theme depending on the time of day.

The DayNight themes already use this implementation, we only need to inherit from them.

In the regular resource for the theme ( values/themes.xml ) we inherit from the light theme, in the “night” ( values-night/themes.The xml ) resource is inherited from the dark theme.

That’s all. We got a library implementation of a dark theme. Now we should maintain the resources for the two themes.

To switch between themes while the app is running, you can use AppCompatDelegate.setDefaultNightMode. That accepts the following parameters:

  • MODE_NIGHT_NO. The light theme;
  • MODE_NIGHT_YES. Dark Theme;
  • MODE_NIGHT_AUTO_BATTERY. Automatic mode. Enables the dark theme if the power saving mode is active;
  • MODE_NIGHT_FOLLOW_SYSTEM. Mode based on system settings.

What should we consider when working with themes and styles?

As I already mentioned, Google has started to officially push the dark theme. I’m sure that many customers have started to ask. “Can we add a dark theme?”. Good, if you are doing everything right from the start and you have no trouble changing the light colors to dark colors, getting a completely repainted application.

Unfortunately, this is not always the case. There are older applications which require a great deal of effort to make the necessary changes.

Let’s try to formulate guidelines for working with styles together:

Color Palette

I think every developer has encountered a situation where some obscure color appears in a new layout that is not yet defined in the app’s palette. What to do in this case?

The right answer is to talk to the designer and try to work out a color palette. Now there are a lot of programs (Zeplin, Sketch, etc) which help you to work out the colors of your images.) that allow you to bring out the basic colors and then reuse them.

The sooner you do it, the less of a headache you’ll have later on.

Call the colors by their proper names

In every app there is a color, which has many variants of brightness. You can start to make up names for them:

It doesn’t look good, don’t you think? The question immediately arises. which color is lighter than tiny or light? ? And if we have a dozen options?

It is best to stick to Google’s concept and add the appropriate brightness to the color names (Google calls this a color variant. colorVariant ):

Read more:  How to Set up Google Okay on Android

That way we can have as many variants of lightness as we want and we won’t have to think up any special names, which is really difficult.

To abstract from a particular color if it varies from theme to theme

Since we are writing an application that will have at least two themes, we cannot afford to reference a specific color if it is implemented differently in the themes.

We can see that in a light theme, for example, the toolbar is colored purple, while in a dark theme it is dark gray. How would we implement this behavior using only the features of the themes?

It’s simple enough. we’ll create an attribute and implement it in light and dark themes with the appropriate color, as described earlier.

Google recommends linking attribute names to semantics of use.

Don’t be afraid to create resource files

When a lot of different attributes are typed into the styles.xml file accumulates a lot of different styles, themes, and attributes, it becomes difficult to maintain.

It’s better to put all the groups into separate files:

Such a simple rule will allow to avoid God-files and therefore it will be easier to support styles.

Overuse to the maximum

What do we do if we want to override an attribute that is available only from a certain API version??

Now for each version of the API we need to make a theme with all parameters? No, of course! We’ll make a base theme that defines the basic attributes available for all API versions and inherit from it in the right API version:

This is how all the themes in the standard library are built.

Use vector resources and tint

I don’t need to tell you why vector resources are good. Everybody knows it (there is a link to the documentation, just in case). Well, and tinting will help us to color them in the theme colors.

To see what tinting is and how to work with it, see this example.

?Android:attr/ vs ?attr/.

When accessing resources, we have the ability to use both system attributes and attributes from the Material Components library. It is important to understand that some attributes exist only from a certain API version. As we all know, calling an inexistent resource leads to a crash (lint will of course tell us if something is wrong, but don’t always rely on it)

In the first case, we are referring to a system resource, as specified by Android. In the second case, to an attribute from the library where backward compatibility is implemented.

It is always better to use the second option.

Always specify a parent for the style

The parent style may contain parameters without which the component will not render correctly, so you should always specify the parent.

Theme, style, or ?

When creating your own themes and styles, it’s great if you specify a prefix that tells you what the style is and what it’s defined for. This naming will make it very easy to structure and extend styles.

Use TextAppearance

It is a good idea to extend basic text styles and use them everywhere.

A lot of useful information can be found at Material Design: Typography, Typography Theming.

I would like to say that styling an application is the responsibility not only of the developers, but also of the designers. Only through close cooperation can we get a really good and beautiful product. Designers should have an understanding of the platform and capabilities of Material Components. It is on their shoulders the responsibility to support the visual component of the application. A special plugin for Sketch, the Material Theme Editor, is available to designers. It’s very easy to choose colors for an app and build screens based on standard components. If your designers don’t already know about it, be sure to tell them.

You can start studying Material Components from the repository on GitHub. Modular and customizable Material Design UI components for Android. It contains a lot of information on standard styles and their capabilities. In addition, there is an application. sample, to try everything at once in practice.

Little about Android

Of the three most popular operating systems (iOS, Android, Windows) of tablets and smartphones, only Google’s child gives the possibility to customize the OS shell for users. This is due to the fact that Android is an open operating system, which often becomes a reason for viruses and spam attacks. But if you are careful with your actions and operations, performed on your device, these problems can be avoided.

Themes can be set because the system allows you to make some adjustments to its structure, so you can see different scenes on the screen of your smartphone or tablet and easily customize the personalization. For many people this is a fairly important point, because they want to customize the axis for themselves: to change the icons of applications (even standard), install widgets that are not available in normal mode, or put some special animation transition between windows. In general, there can be many reasons, but the main thing is how to do it. So let’s talk about how to change the theme of your tablet.

The easiest method to install the desired theme on Android is to download themes from Play Market. In the search box, enter the word “theme” or “theme”, and then type in the desired keywords to immediately get a selection on the topic of interest. Market independently filters the results output, selecting for you those themes that are suitable for the model of the smartphone, as well as its system requirements. If the list was not filtered, just read the description of the topic to make sure it fits the phone. After downloading you just need to run the file with the theme and then follow the further instructions of the software to change the design.

To install a theme downloaded from a third-party source, you will need to do more work:

  • First, your smartphone or tablet must be allowed to install apps from third-party/unknown sources.
  • Transfer the downloaded theme files to your SD card. It is important that the theme file has an APK extension.
  • Launch the software to install applications. It can be downloaded from “Google Market”, for example AppInstaller will do.
  • The installer will scan the SD card. In the list of files that the utility will prompt you to install, select the theme you are interested in.
  • Next, follow the instructions of the app installer software to install the theme.