You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p>Talk about Googling the same sort of thing for Android APIs (setting the hint color).</p>
1746
+
<p>Much like with iOS, if you’ve not a native Android developer, figuring out how to accomplish a task on Android often starts with a web search. If you run a <ahref="https://www.google.com/#q=style%20android%20text%20field%20hint%20text">search for “style Android text field hint text”</a>, you’ll end up on a <ahref="http://stackoverflow.com/questions/6438478/sethinttextcolor-in-edittext">Stack Overflow answer</a> that recommends using a <ahref="http://developer.android.com/reference/android/widget/TextView.html#attr_android:textColorHint"><code>android.widget.TextView</code>’s <code>setTextHintColor()</code> method</a>. Let’s alter our code to do that.</p>
1747
1747
<h4class="exercise-start">
1748
-
<b>Exercise</b>: ???
1748
+
<b>Exercise</b>: Change hint colors on Android
1749
1749
</h4>
1750
1750
1751
1751
<p>Open <code>app/utils/hint-util.ts</code> and replace the existing contents of the file with the following code:</p>
1752
1752
<pre><codeclass="lang-TypeScript">import {Color} from "color";
1753
1753
import {TextField} from "ui/text-field";
<p>Remember from the previous section that NativeScript makes native objects available via a <code>android</code> property. In this case <code>args.view.android</code> refers to a <ahref="http://developer.android.com/reference/android/widget/TextView.html"><code>TextView</code></a>, and therefore has the <code>setHintTextColor()</code> method that the Stack Overflow post said to call.</p>
1776
+
<p>One other thing to notice is the if checks that you added around each of the native calls. Your TypeScript code runs across both platforms, and iOS APIs are not available on Android (and vice versa). Testing for the existence of the native object properties is a common way to fork your code in NativeScript to avoid errors. And with this change in place, your hint colors on Android are now far more legible.</p>
1777
+
<p><imgsrc="images/chapter6/android/2.png" alt="Better contrast on Android"></p>
1778
+
<p>Let’s look at one last way we can improve the look of this app with native code.</p>
1779
1779
<h3id="customizing-the-status-bar">Customizing the status bar</h3>
1780
-
<p>Talk about status bars.</p>
1780
+
<p>At the time of this writing, NativeScript does not expose a way to make translucent status bars—aka status bars that you can see through. There is an <ahref="https://github.com/NativeScript/NativeScript/issues/601">open issue requesting this feature</a>, but as with anything else when building with NativeScript, you don’t have to be limited by what NativeScript provides out of the box. Let’s look at how you can use that power to make your status bars look a little nicer.</p>
1781
1781
<h4class="exercise-start">
1782
-
<b>Exercise</b>: ???
1782
+
<b>Exercise</b>: Making translucent status bars
1783
1783
</h4>
1784
1784
1785
-
<p>Open <code>app/main.ts</code> and replace the contents of the file with the following code:</p>
1785
+
<p>Sometimes accomplishing tasks with native code is simple, as it was with setting hint text on Android, and sometimes it takes a little more work. Because setting a status bar’s appearance is slightly more involved, the code has been prepopulated in <code>app/utils/status-bar-util.ts</code>. There are a few comments the link to detailed information on the techniques used, if you’re curious about how it all works.</p>
1786
+
<p>Because this code changes the appearance of the status bar, we’ll want to call this method as soon as possible, so that the status bar doesn’t awkwardly update after the app has already loaded. Therefore to use this new utility, open <code>app/main.ts</code> and replace the contents of the file with the following code, which calls a new <code>setStatusBarColors()</code> before the app is bootstrapped.</p>
1786
1787
<pre><codeclass="lang-TypeScript">import {nativeScriptBootstrap} from "nativescript-angular/application";
1787
1788
import {AppComponent} from "./app.component";
1788
1789
import {setStatusBarColors} from "./utils/status-bar-util";
1789
1790
1790
1791
setStatusBarColors();
1791
1792
nativeScriptBootstrap(AppComponent);
1792
1793
</code></pre>
1793
-
<p>Next, open <code>app/platform.ios.css</code> and paste in the following code:</p>
1794
+
<p>Finally, because a translucent status bar continues to take up space on iOS, open <code>app/platform.ios.css</code> and paste in the following code, which bumps the content of the page on top of the status bar.</p>
1794
1795
<pre><codeclass="lang-CSS">Page {
1795
1796
margin-top: -20;
1796
1797
}
1797
1798
</code></pre>
1798
1799
<divclass="exercise-end"></div>
1799
1800
1800
-
<p>Talk about what just happened.</p>
1801
-
<p>TODO: Insert images</p>
1801
+
<p>And with that, your status bar is not translucent on iOS and Android:</p>
1802
+
<p><imgsrc="images/chapter6/android/3.png" alt="Updated status bar on Android">
1803
+
<imgsrc="images/chapter6/ios/3.png" alt="Updated status bar on iOS"></p>
1802
1804
<p>And... that's it! You've created a functional, cross-platform, backend-driven app to manage your grocery list. In the process you've created a unique UI for Android and iOS, leveraged NativeScript plugins and npm modules, learned how to log in and register, managed backend services, created a list with add and delete functionality, and more. </p>
1803
1805
<p>Congratulations! Feel free to <ahref="https://twitter.com/intent/tweet?text=I%20just%20built%20an%20iOS%20and%20Android%20app%20using%20@NativeScript%20%F0%9F%8E%89.%20You%20can%20too!%20http://docs.nativescript.org/start/getting-started%20%23opensource">share your accomplishment on Twitter</a> or <ahref="https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fdocs.nativescript.org%2Fstart%2Fgetting-started&p%5B">Facebook</a> to impress your friends 😀.</p>
1804
-
<blockquote>
1805
-
<p><strong>TIP</strong>:</p>
1806
-
<ul>
1807
-
<li>If you're curious about how NativeScript makes it possible to directly invoke iOS and Android APIs, you can read about <ahref="http://developer.telerik.com/featured/nativescript-works/">“How NativeScript Works”</a> on our blog.</li>
1808
-
<li>Remember that the <ahref="https://github.com/NativeScript/sample-Groceries/tree/angular-end">Groceries app's “angular-end” branch</a> has the final state of this tutorial. Feel free to refer back to it at any time.</li>
Copy file name to clipboardExpand all lines: src/chapters/chapter6.md
+16-16Lines changed: 16 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -104,10 +104,10 @@ Let’s move onto how to accomplish this same hint color task on Android.
104
104
105
105
### Accessing Android APIs
106
106
107
-
Talk about Googling the same sort of thing for Android APIs (setting the hint color).
107
+
Much like with iOS, if you’ve not a native Android developer, figuring out how to accomplish a task on Android often starts with a web search. If you run a [search for “style Android text field hint text”](https://www.google.com/#q=style%20android%20text%20field%20hint%20text), you’ll end up on a [Stack Overflow answer](http://stackoverflow.com/questions/6438478/sethinttextcolor-in-edittext) that recommends using a [`android.widget.TextView`’s `setTextHintColor()` method](http://developer.android.com/reference/android/widget/TextView.html#attr_android:textColorHint). Let’s alter our code to do that.
108
108
109
109
<h4class="exercise-start">
110
-
<b>Exercise</b>: ???
110
+
<b>Exercise</b>: Change hint colors on Android
111
111
</h4>
112
112
113
113
Open `app/utils/hint-util.ts` and replace the existing contents of the file with the following code:
@@ -116,7 +116,6 @@ Open `app/utils/hint-util.ts` and replace the existing contents of the file with
116
116
import {Color} from"color";
117
117
import {TextField} from"ui/text-field";
118
118
119
-
declarevar android:any;
120
119
declarevar NSAttributedString:any;
121
120
declarevar NSDictionary:any;
122
121
declarevar NSForegroundColorAttributeName:any;
@@ -138,21 +137,25 @@ export function setHintColor(args: { view: TextField, color: Color }) {
138
137
139
138
<divclass="exercise-end"></div>
140
139
141
-
Talk about what just happened.
140
+
Remember from the previous section that NativeScript makes native objects available via a `android` property. In this case `args.view.android` refers to a [`TextView`](http://developer.android.com/reference/android/widget/TextView.html), and therefore has the `setHintTextColor()` method that the Stack Overflow post said to call.
142
141
143
-
TODO: Insert gifs
142
+
One other thing to notice is the if checks that you added around each of the native calls. Your TypeScript code runs across both platforms, and iOS APIs are not available on Android (and vice versa). Testing for the existence of the native object properties is a common way to fork your code in NativeScript to avoid errors. And with this change in place, your hint colors on Android are now far more legible.
144
143
145
-
Transition to status bar discussion
144
+

145
+
146
+
Let’s look at one last way we can improve the look of this app with native code.
146
147
147
148
### Customizing the status bar
148
149
149
-
Talk about status bars.
150
+
At the time of this writing, NativeScript does not expose a way to make translucent status bars—aka status bars that you can see through. There is an [open issue requesting this feature](https://github.com/NativeScript/NativeScript/issues/601), but as with anything else when building with NativeScript, you don’t have to be limited by what NativeScript provides out of the box. Let’s look at how you can use that power to make your status bars look a little nicer.
150
151
151
152
<h4class="exercise-start">
152
-
<b>Exercise</b>: ???
153
+
<b>Exercise</b>: Making translucent status bars
153
154
</h4>
154
155
155
-
Open `app/main.ts` and replace the contents of the file with the following code:
156
+
Sometimes accomplishing tasks with native code is simple, as it was with setting hint text on Android, and sometimes it takes a little more work. Because setting a status bar’s appearance is slightly more involved, the code has been prepopulated in `app/utils/status-bar-util.ts`. There are a few comments the link to detailed information on the techniques used, if you’re curious about how it all works.
157
+
158
+
Because this code changes the appearance of the status bar, we’ll want to call this method as soon as possible, so that the status bar doesn’t awkwardly update after the app has already loaded. Therefore to use this new utility, open `app/main.ts` and replace the contents of the file with the following code, which calls a new `setStatusBarColors()` before the app is bootstrapped.
Next, open `app/platform.ios.css` and paste in the following code:
169
+
Finally, because a translucent status bar continues to take up space on iOS, open `app/platform.ios.css` and paste in the following code, which bumps the content of the page on top of the status bar.
167
170
168
171
```CSS
169
172
Page {
@@ -173,14 +176,11 @@ Page {
173
176
174
177
<divclass="exercise-end"></div>
175
178
176
-
Talk about what just happened.
179
+
And with that, your status bar is not translucent on iOS and Android:
177
180
178
-
TODO: Insert images
181
+

182
+

179
183
180
184
And... that's it! You've created a functional, cross-platform, backend-driven app to manage your grocery list. In the process you've created a unique UI for Android and iOS, leveraged NativeScript plugins and npm modules, learned how to log in and register, managed backend services, created a list with add and delete functionality, and more.
181
185
182
186
Congratulations! Feel free to [share your accomplishment on Twitter](https://twitter.com/intent/tweet?text=I%20just%20built%20an%20iOS%20and%20Android%20app%20using%20@NativeScript%20%F0%9F%8E%89.%20You%20can%20too!%20http://docs.nativescript.org/start/getting-started%20%23opensource) or [Facebook](https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fdocs.nativescript.org%2Fstart%2Fgetting-started&p%5B) to impress your friends 😀.
183
-
184
-
> **TIP**:
185
-
> * If you're curious about how NativeScript makes it possible to directly invoke iOS and Android APIs, you can read about [“How NativeScript Works”](http://developer.telerik.com/featured/nativescript-works/) on our blog.
186
-
> * Remember that the [Groceries app's “angular-end” branch](https://github.com/NativeScript/sample-Groceries/tree/angular-end) has the final state of this tutorial. Feel free to refer back to it at any time.
0 commit comments