Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7c6b7f7b authored by David Friedman's avatar David Friedman
Browse files

Docs: Corrections to Android Studio "Getting Started"-type documentation.

Bug: 25458018

Change-Id: Ibbecffc00461ba61e3f5f596b34a7b049b9193ec
parent df43875e
Loading
Loading
Loading
Loading
−1.38 KiB (5.07 KiB)
Loading image diff...
−1.53 KiB (5.08 KiB)
Loading image diff...
+34 −34
Original line number Diff line number Diff line
@@ -71,10 +71,10 @@ android.view.View} objects.</p>
<h2 id="LinearLayout">Create a Linear Layout</h2>

<ol>
<li>In Android Studio, from the <code>res/layout</code> directory, open the <code>activity_my.xml</code>
<li>In Android Studio, from the <code>res/layout</code> directory, open the {@code content_my.xml}
file.
<p>The BlankActivity template you chose when you created this project includes the
<code>activity_my.xml</code> file with a {@link android.widget.RelativeLayout} root view and a
<code>content_my.xml</code> file with a {@link android.widget.RelativeLayout} root view and a
{@link android.widget.TextView} child view.</p>
</li>
<li>In the <strong>Preview</strong> pane, click the Hide icon <img src="{@docRoot}images/tools/as-hide-side.png"
@@ -92,14 +92,15 @@ file.

</p>The result looks like this:</p>

<p class="code-caption">res/layout/activity_my.xml</p>
<pre>
&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >
&lt;/LinearLayout>
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:showIn="@layout/activity_my"&gt;
</pre>

<p>{@link android.widget.LinearLayout} is a view group (a subclass of {@link
@@ -131,7 +132,7 @@ href="{@docRoot}guide/topics/ui/declaring-layout.html">Layout</a> guide.</p>
the {@link android.widget.EditText} object's properties.</p>

<ol>
<li>In the <code>activity_my.xml</code> file, within the
<li>In the <code>content_my.xml</code> file, within the
{@link android.widget.LinearLayout &lt;LinearLayout>} element, define an
{@link android.widget.EditText &lt;EditText>} element with the <code>id</code> attribute
set to <code>@+id/edit_message</code>.</li>
@@ -142,7 +143,6 @@ set to <code>@+id/edit_message</code>.</li>

<p>The {@link android.widget.EditText &lt;EditText>} element should read as follows:</p>

<p class="code-caption">res/layout/activity_my.xml</p>
<pre>
&lt;EditText android:id="@+id/edit_message"
    android:layout_width="wrap_content"
@@ -232,12 +232,10 @@ the same name does not cause collisions.</p>
<li>Add a line for a string named <code>"button_send"</code> with the value, "Send".
<p>You'll create the button that uses this string in the next section.</p>
</li>
<li>Remove the line for the <code>"hello world"</code> string.</li>
</ol>

<p>The result for <code>strings.xml</code> looks like this:</p>

<p class="code-caption">res/values/strings.xml</p>
<pre>
&lt;?xml version="1.0" encoding="utf-8"?>
&lt;resources>
@@ -245,7 +243,6 @@ the same name does not cause collisions.</p>
    &lt;string name="edit_message">Enter a message&lt;/string>
    &lt;string name="button_send">Send&lt;/string>
    &lt;string name="action_settings">Settings&lt;/string>
    &lt;string name="title_activity_main">MainActivity&lt;/string>
&lt;/resources>
</pre>

@@ -264,7 +261,7 @@ class.</p>
<h2 id="Button">Add a Button</h2>

<ol>
<li>In Android Studio, from the <code>res/layout</code> directory, edit the <code>activity_my.xml</code>
<li>In Android Studio, from the <code>res/layout</code> directory, edit the <code>content_my.xml</code>
file.</li>
<li>Within the
{@link android.widget.LinearLayout &lt;LinearLayout>} element, define a
@@ -280,13 +277,15 @@ resource you defined in the previous section.</li>

<p>Your {@link android.widget.LinearLayout &lt;LinearLayout>} should look like this:</p>

<p class="code-caption">res/layout/activity_my.xml</p>
<pre>
&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" &gt;
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:showIn="@layout/activity_my"&gt;
        &lt;EditText android:id="@+id/edit_message"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
@@ -303,8 +302,8 @@ resource you defined in the previous section.</li>
attribute, because it won't be referenced from the activity code.</p>

<p>The layout is currently designed so that both the {@link android.widget.EditText} and {@link
android.widget.Button} widgets are only as big as necessary to fit their content, as shown in
figure 2.</p>
android.widget.Button} widgets are only as big as necessary to fit their content, as Figure 2 shows.
</p>

<img src="{@docRoot}images/training/firstapp/edittext_wrap.png" />
<p class="img-caption"><strong>Figure 2.</strong> The {@link android.widget.EditText} and {@link
@@ -339,13 +338,12 @@ given the space they require.</p>
the following:</p>

<ol>
<li>In the <code>activity_my.xml</code> file, assign the
<li>In the <code>content_my.xml</code> file, assign the
{@link android.widget.EditText &lt;EditText>} element's <code>layout_weight</code> attribute a value
of <code>1</code>.</li>
<li>Also, assign {@link android.widget.EditText &lt;EditText>} element's <code>layout_width</code>
attribute a value of <code>0dp</code>.

<p class="code-caption">res/layout/activity_my.xml</p>
<pre>
&lt;EditText
    android:layout_weight="1"
@@ -371,16 +369,18 @@ android.widget.LinearLayout}.</p>
</li>
</ol>

<p>Here’s how your complete <code>activity_my.xml</code>layout file should now look:</p>
<p>Here’s how your complete <code>content_my.xml</code>layout file should now look:</p>

<p class="code-caption">res/layout/activity_my.xml</p>
<pre>
&lt;?xml version="1.0" encoding="utf-8"?>
&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:app="http://schemas.android.com/apk/res-auto"
   xmlns:tools="http://schemas.android.com/tools"
   android:orientation="horizontal"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
    android:orientation="horizontal">
   app:layout_behavior="@string/appbar_scrolling_view_behavior"
   tools:showIn="@layout/activity_my"&gt;
    &lt;EditText android:id="@+id/edit_message"
        android:layout_weight="1"
        android:layout_width="0dp"
@@ -405,9 +405,9 @@ results:</p>
    style="vertical-align:baseline;margin:0; max-height:1em" />.</li>
  <li>Or from a command line, change directories to the root of your Android project and
execute:
<pre>
ant debug
adb install bin/MyFirstApp-debug.apk
<pre class="no-pretty-print">
$ ant debug
adb install -r app/build/outputs/apk/app-debug.apk
</pre></li>
</ul>

+30 −62
Original line number Diff line number Diff line
@@ -53,16 +53,11 @@ lesson.</p>
      <li>If you don't have a project opened, in the <strong>Welcome</strong> screen, click <strong>
        New Project</strong>.</li>
      <li>If you have a project opened, from the <strong>File</strong> menu, select <strong>New
        Project</strong>.</li>
        Project</strong>. The <em>Create New Project</em> screen appears.</li>
    </ul>
  </li>
  <div class="figure" style="width:420px">
    <img src="{@docRoot}images/training/firstapp/studio-setup-1.png" alt="" />
    <p class="img-caption"><strong>Figure 1.</strong> Configuring a new project in Android Studio.</p>
  </div>
  <li>Under <strong>Configure your new project</strong>, fill in the fields as shown in figure 1
    and click <strong>Next</strong>.
    <p>It will probably be easier to follow these lessons if you use the same values as shown.</p>
  <li>Fill out the fields on the screen, and click <strong>Next</strong>.
    <p>It is easier to follow these lessons if you use the same values as shown.</p>
    <ul>
      <li><strong>Application Name</strong> is the app name that appears to users.
          For this project, use "My First App."</li>
@@ -102,7 +97,7 @@ lesson.</p>
  </div>
  <li>Under <strong>Add an activity to &lt;<em>template</em>&gt;</strong>, select <strong>Blank
    Activity</strong> and click <strong>Next</strong>.</li>
  <li>Under <strong>Choose options for your new file</strong>, change the
  <li>Under <strong>Customize the Activity</strong>, change the
    <strong>Activity Name</strong> to <em>MyActivity</em>. The <strong>Layout Name</strong> changes
    to <em>activity_my</em>, and the <strong>Title</strong> to <em>MyActivity</em>. The
    <strong>Menu Resource Name</strong> is <em>menu_my</em>.
@@ -114,10 +109,18 @@ moment to review the most important of these:</p>

<dl>
  <dt><code>app/src/main/res/layout/activity_my.xml</code></dt>
  <dd>This is the XML layout file for the activity you added when you created the project with Android
    Studio. Following the New Project workflow, Android Studio presents this file with both a text
    view and a preview of the screen UI. The file includes some default settings and a <code>TextView</code>
    element that displays the message, "Hello world!"</dd>
  <dd>This XML layout file is for the activity you added when you created the project
  with Android Studio. Following the New Project workflow, Android Studio presents this file
  with both a text
    view and a preview of the screen UI. The file contains some default interface elements
    from the material design library, including the
    <a href="{@docRoot}training/appbar/index.html">app bar</a> and a floating action button.
    It also includes a separate layout file with the main content.</dd>

  <dt><code>app/src/main/res/layout/content_my.xml</code></dt>
  <dd>This XML layout file resides in {@code activity_my.xml}, and contains some settings and
  a {@code TextView} element that displays the message, "Hello world!".</dd>

  <dt><code>app/src/main/java/com.mycompany.myfirstapp/MyActivity.java</code></dt>
  <dd>A tab for this file appears in Android Studio when the New Project workflow finishes. When you
    select the file you see the class definition for the activity you created. When you build and
@@ -159,59 +162,24 @@ moment to review the most important of these:</p>
<p>Note also the <code>/res</code> subdirectories that contain the
<a href="{@docRoot}guide/topics/resources/overview.html">resources</a> for your application:</p>
<dl>
  <dt><code>drawable<em>&lt;density&gt;</em>/</code></dt>
    <dd>Directories for drawable objects (such as bitmaps) that are designed for various densities,
    such as medium-density (mdpi) and high-density (hdpi) screens. Other drawable directories
    contain assets designed for other screen densities.
    Here you'll find the ic_launcher.png that appears when you run the default app.</dd>
  <dt><code>drawable<em>-&lt;density&gt;</em>/</code></dt>
    <dd>Directories for <a href="{@docRoot}guide/topics/resources/drawable-resource.html">
    drawable resources</a>, other than launcher icons, designed
    for various <a href="{@docRoot}training/multiscreen/screendensities.html">densities</a>.
</dd>
  <dt><code>layout/</code></dt>
    <dd>Directory for files that define your app's user interface like activity_my.xml,
      discussed above, which describes a basic layout for the MyActivity class.</dd>
    <dd>Directory for files that define your app's user interface like {@code activity_my.xml},
      discussed above, which describes a basic layout for the {@code MyActivity}
      class.</dd>
  <dt><code>menu/</code></dt>
    <dd>Directory for files that define your app's menu items.</dd>
  <dt><code>mipmap/</code></dt>
    <dd>Launcher icons reside in the {@code mipmap/} folder rather than the
    {@code drawable/} folders. This folder contains the {@code ic_launcher.png} image
    that appears when you run the default app.</dd>
  <dt><code>values/</code></dt>
    <dd>Directory for other XML files that contain a collection of resources, such as
      string and color definitions. The strings.xml file defines the "Hello world!" string that
      displays when you run the default app.</dd>
      string and color definitions.</dd>
</dl>

<p>To run the app, continue to the <a href="running-app.html">next lesson</a>.</p>

<h2 id="CommandLine">Create a Project with Command Line Tools</h2>

<p>If you're not using the Android Studio IDE, you can instead create your project
using the SDK tools from a command line:</p>

<ol>
  <li>Change directories into the Android SDK’s <code>sdk/</code> path.</li>
  <li>Execute:
<pre class="no-pretty-print">tools/android list targets</pre>
<p>This prints a list of the available Android platforms that you’ve downloaded for your SDK. Find
the platform against which you want to compile your app. Make a note of the target ID. We
recommend that you select the highest version possible. You can still build your app to
support older versions, but setting the build target to the latest version allows you to optimize
your app for the latest devices.</p>
<p>If you don't see any targets listed, you need to
install some using the Android SDK
Manager tool. See <a href="{@docRoot}sdk/installing/adding-packages.html">Adding SDK
  Packages</a>.</p></li>
  <li>Execute:
<pre class="no-pretty-print">
android create project --target &lt;target-id> --name MyFirstApp \
--path &lt;path-to-workspace>/MyFirstApp --activity MyActivity \
--package com.example.myfirstapp
</pre>
<p>Replace <code>&lt;target-id></code> with an ID from the list of targets (from the previous step)
and replace
<code>&lt;path-to-workspace></code> with the location in which you want to save your Android
projects.</p></li>
</ol>

<p class="note"><strong>Tip:</strong> Add the <code>platform-tools/</code> as well as the
<code>tools/</code> directory to your <code>PATH</code> environment variable.</p>

<p>Your Android project is now a basic "Hello World" app that contains some default files.
To run the app, continue to the <a href="running-app.html">next lesson</a>.</p>


+8 −10
Original line number Diff line number Diff line
@@ -88,7 +88,7 @@ from the toolbar.</li>
  using the Gradle wrapper script (<code>gradlew assembleRelease</code>).

  <p>This creates your debug <code>.apk</code> file inside the module <code>build/</code>
  directory, named <code>MyFirstApp-debug.apk</code>.  </p>
  directory, named <code>app-debug.apk</code>.  </p>

  <p>On Windows platforms, type this command:</p>

@@ -112,7 +112,7 @@ $ ./gradlew assembleDebug

  <p>Make sure the Android SDK <code>platform-tools/</code> directory is included in your
  <code>PATH</code> environment variable, then execute:
  <pre class="no-pretty-print">adb install app/build/outputs/MyFirstApp-debug.apk</pre><p>
  <pre class="no-pretty-print">$ adb install app/build/outputs/apk/app-debug.apk</pre><p>
  <p>On your device, locate <em>MyFirstApp</em> and open it.</p>

<p>That's how you build and run your Android app on a device!
@@ -134,7 +134,9 @@ device.</p>
  <li>Launch the Android Virtual Device Manager:
    <ul>
      <li>In Android Studio, select <strong>Tools &gt; Android &gt; AVD Manager</strong>, or click
  the AVD Manager icon <img src="{@docRoot}images/tools/avd-manager-studio.png" style="vertical-align:bottom;margin:0;height:19px"> in the toolbar.</li>
  the AVD Manager icon <img src="{@docRoot}images/tools/avd-manager-studio.png"
  style="vertical-align:bottom;margin:0;height:19px"> in the toolbar. The
  <em>AVD Manager</em> screen appears.</li>
      <li>Or, from the command line, change directories to
      <code>sdk/</code> and execute:
        <pre class="no-pretty-print">tools/android avd</pre>
@@ -144,12 +146,8 @@ device.</p>
        </li>
    </ul>

  <img src="{@docRoot}images/studio-avdmgr-firstscreen.png" alt=""
  style="margin-top:1em">
  <p class="img-caption"><strong>Figure 1.</strong> The AVD Manager main screen shows your current virtual devices.</p>

  </li>
  <li>On the AVD Manager main screen (figure 1), click <strong>Create Virtual Device</strong>.</li>
  <li>On the AVD Manager main screen, click <strong>Create Virtual Device</strong>.</li>
  <li>In the Select Hardware window, select a device configuration, such as Nexus 6,
  then click <strong>Next</strong>.
  </li>
@@ -183,7 +181,7 @@ When you do, <em>My First App</em> appears on the emulator screen.</p>
  <code>PATH</code> environment variable.</li>
  <li>Execute this command:
   <p>
   <pre class="no-pretty-print">adb install app/build/outputs/MyFirstApp-debug.apk</pre>
   <pre class="no-pretty-print">$ adb install app/build/outputs/apk/apk-debug.apk</pre>
   </p>
  </li>
  <li>On the emulator, locate <em>MyFirstApp</em> and open it.</li>
Loading