|
2 | 2 |
|
3 | 3 | <span class="badge-buymeacoffee"><a href="https://www.buymeacoffee.com/miga" title="donate"><img src="https://img.shields.io/badge/buy%20me%20a%20coke-donate-orange.svg" alt="Buy Me A Coke donate button" /></a></span> <a href="https://github.com/sponsors/m1ga"><img src="./images/gh_sponsor.png" title="Sponsor me"/></a>
|
4 | 4 |
|
5 |
| -## Android Adaptive Icons |
6 |
| - |
7 |
| - |
8 |
| - |
9 |
| -<!-- START doctoc generated TOC please keep comment here to allow auto update --> |
10 |
| -<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> |
11 |
| -**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)* |
12 |
| - |
13 |
| -- [From zero to app](#from-zero-to-app) |
14 |
| - - [Android Adaptive Icons](#android-adaptive-icons) |
15 |
| - - [Setup](#setup) |
16 |
| - - [Create the icon](#create-the-icon) |
17 |
| - - [Titanium app](#titanium-app) |
18 |
| - |
19 |
| -<!-- END doctoc generated TOC please keep comment here to allow auto update --> |
20 |
| - |
21 |
| -Starting with Android 8 (API 26) Google introduced the concept of `Adaptive Icons` which can display a variety of shapes across different device models. The main icon (foreground) is separated from the background (image, color, xml) and a mask is applied on top of the image. |
22 |
| -If you create a new app and add an Android icon it will look like this with the default setup: |
23 |
| - |
24 |
| -<img src="images/icon_app.png"/><br/> |
25 |
| -the blue background is not filling up the whole space and the icon is a bit small. In this tutorial we will create an Adaptive Icon that will blend in with your other apps. |
26 |
| - |
27 |
| -### Setup |
28 |
| - |
29 |
| -The best and easiest way to do this is to use Android Studio. If you don't have it installed you can go to https://developer.android.com/studio and download it for free. |
30 |
| - |
31 |
| -If your icon has just a plain color in the background you can create a transparent version of the foreground element and save that. |
32 |
| - |
33 |
| -<img src="images/icon_transparent.jpg"/><br/> |
34 |
| - |
35 |
| -If your background is a gradient or contains multiple colors you save that as a different file. |
36 |
| - |
37 |
| -### Create the icon |
38 |
| - |
39 |
| -1. Open up Android Studio and create a new project: |
40 |
| - |
41 |
| - <img src="images/icon_studio1.png"/><br/> |
42 |
| - |
43 |
| - Select an empty activity and just click next to create the project. We will just use the Asset Studio for the icon - the rest of project is not needed. |
44 |
| - |
45 |
| -2. Right click on `app` and select `New - Image Asset`: |
46 |
| - |
47 |
| - <img src="images/icon_studio2.png"/><br/> |
48 |
| - |
49 |
| -3. Now you will see the Asset Studio with the default icon/setup: |
50 |
| - |
51 |
| - <img src="images/icon_studio3.png"/><br/> |
52 |
| - |
53 |
| -4. Rename the icon name to `appicon` (can be anything) and in the source asset select `Asset Type: Image` and select your icon in the `Path` field: |
54 |
| - |
55 |
| - <img src="images/icon_studio4.png"/><br/> |
56 |
| - |
57 |
| - With the `Scaling - Resize` slider you can adjust the size of the foreground element. |
58 |
| - |
59 |
| -5. Now we will switch to the `Background Layer` tab and either set the plain color or load the background image: |
60 |
| - |
61 |
| - <img src="images/icon_studio5.png"/><br/> |
62 |
| - |
63 |
| - That's all! You can click next. |
64 |
| - |
65 |
| -6. In the last screen you will see all the files in the `res` folder that you will need to copy over to your Titanium project: |
66 |
| - |
67 |
| - <img src="images/icon_studio6.png"/><br/> |
68 |
| - |
69 |
| -### Titanium app |
70 |
| - |
71 |
| -To use the Adaptive Icon in your Titanium app you have to add this to your tiapp.xml file: |
72 |
| - |
73 |
| -```xml |
74 |
| -<android xmlns:android="http://schemas.android.com/apk/res/android"> |
75 |
| - <manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1"> |
76 |
| - |
77 |
| - <application android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" /> |
78 |
| - |
79 |
| - </manifest> |
80 |
| -</android> |
81 |
| -``` |
82 |
| - |
83 |
| -where `appicon` is the name you have put into the `name` box in step 4. |
84 |
| - |
85 |
| -Now we can copy over all the files: |
86 |
| - |
87 |
| -<table> |
88 |
| -<tr> |
89 |
| -<th>Android Studio:<br/>[project-name]/app/src/main/res/</th> |
90 |
| -<th>Appcelerator Titanium:<br/>[app-name]/platform/android/res</th> |
91 |
| -</tr> |
92 |
| - |
93 |
| -<tr> |
94 |
| -<td>/mipmap-anydpi-v26/appicon_round.xml</td> |
95 |
| -<td>/mipmap-anydpi-v26/appicon_round.xml</td> |
96 |
| -</tr> |
97 |
| - |
98 |
| -<tr> |
99 |
| -<td>/mipmap-anydpi-v26/appicon.xml</td> |
100 |
| -<td>/mipmap-anydpi-v26/appicon.xml</td> |
101 |
| -</tr> |
102 |
| - |
103 |
| -<tr> |
104 |
| -<td>/mipmap-hdpi/appicon_foreground.png</td> |
105 |
| -<td>/mipmap-hdpi/appicon_foreground.png</td> |
106 |
| -</tr> |
107 |
| - |
108 |
| -<tr> |
109 |
| -<td>/mipmap-hdpi/appicon_round.png</td> |
110 |
| -<td>/mipmap-hdpi/appicon_round.png</td> |
111 |
| -</tr> |
112 |
| - |
113 |
| -<tr> |
114 |
| -<td>/mipmap-hdpi/appicon.png</td> |
115 |
| -<td>/mipmap-hdpi/appicon.png</td> |
116 |
| -</tr> |
117 |
| - |
118 |
| -<tr> |
119 |
| -<td><i>same for all the other mipmap-* folders</i></td> |
120 |
| -<td><i>same for all the other mipmap-* folders</i></td> |
121 |
| -</tr> |
122 |
| - |
123 |
| -<tr> |
124 |
| -<td>/values/appicon_background.xml</td> |
125 |
| -<td>/values/appicon_background.xml</td> |
126 |
| -</tr> |
127 |
| - |
128 |
| -</table> |
129 |
| - |
130 |
| -When you compile your app it will show the correct icon now: |
131 |
| - |
132 |
| -<img src="images/icon_app_new.png"/><br/> |
| 5 | +visit https://fromzerotoapp.com/android-adaptive-icons/ |
0 commit comments