Aperçu de notre première application Android développée avec Android Studio


Assistant de création d'un nouveau projet : étape 1/4

Assistant de création d'un nouveau projet : étape 2/4

Assistant de création d'un nouveau projet : étape 3/4

Assistant de création d'un nouveau projet : étape 4/4

Fenêtre principale d'un nouveau projet Android Studio
A
B
C
D
E
F


Assistant de création d'un AVD : étape 1/3

Assistant de création d'un AVD : étape 2/3

Assistant de création d'un AVD : étape 3/3




<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="edu.android.helloworld" >
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>package edu.android.helloworld;
public final class R {
public static final class attr {
}
public static final class dimen {
public static final int activity_horizontal_margin=0x7f070025;
public static final int activity_vertical_margin=0x7f070026;
}
public static final class drawable {
public static final int ic_launcher=0x7f020000;
}
public static final class id {
public static final int title=0x7f080027;
}
public static final class layout {
public static final int activity_main=0x7f030017;
public static final int support_simple_spinner_dropdown_item=0x7f030018;
}
public static final class menu {
public static final int menu_main=0x7f0c0000;
}
public static final class string {
public static final int action_settings=0x7f0a0010;
public static final int app_name=0x7f0a0011;
public static final int hello_world=0x7f0a0012;
}
}
MainActivity

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<EditText android:id="@+id/editTxt"
android:hint="@string/editMsg"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_width="0dp" />
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/button_send" />
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">HelloWorld</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
<string name="editMsg">Enter a message</string>
<string name="sendBtn">Send</string>
</resources>

MainActivity
DisplayMessageActivity
/** Called when the user clicks the Send button */
public void sendMessage(View view) {
Intent intent = new Intent(this, DisplayMessageActivity.class);
EditText editText = (EditText) findViewById(R.id.editTxt);
String message = editText.getText().toString();
intent.putExtra("edu.android.helloworld.MESSAGE", message);
startActivity(intent);
}package edu.android.helloworld;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.MenuItem;
import android.widget.TextView;
public class DisplayMessageActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//TODO
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}<application ... >
...
<activity
android:name="edu.android.helloworld.DisplayMessageActivity"
android:label="@string/title_activity_display_message"
android:parentActivityName="edu.android.helloworld.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="edu.android.helloworld.MainActivity" />
</activity>
</application><resources>...
<string name="title_activity_display_message">My Message</string>
</resources> @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the message from the intent
Intent intent = getIntent();
String message = intent.getStringExtra("edu.android.helloworld.MESSAGE");
// Create the text view
TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(message);
// Set the text view as the activity layout
setContentView(textView);
}