インテリジェントシステム
第2回
Android の主要機能
• 画面の設計
• アプリケーションの状態遷移
Android におけるアプリケーシ
ョン
• 複数ファイルを用いて定義
– s rc
• クラス定義
– res
• リソース
– assets
• 画像や音声などの元データ
– AndroidManifest.xml ファイルで要素を一つにまとめ
る
• 必ず Activity クラスを含む
– アプリケーションの状態遷移を司る
Eclipse の画面を見てみると
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="lecture_android.android2"
android:versionCode="1"
android:versionName="1.0.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Sample2"
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>
AndroidManifest.xml
“ ”@ 他のファイル(ここではリソースファイル)に
定義がある
Activity の
クラス名
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, Sample2</string>
<string name="app_name">Sample2</string>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, Sample2</string>
<string name="app_name"> サンプル 2</string>
</resources>
リソースファイルの働き
(values.strings.xml)
クイズ
なぜこんなことをするのか??
import android.app.Activity;
import android.os.Bundle;
public class Sample2 extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle avedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
最も単純な Activity
リソースファイル
から作られる
画面定義
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
mlns:android="http://schemas.android.com/apk/res/a
ndroid"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
</LinearLayout>
リソースファイル ( main.xml)
文字の属性を変える
• 色
• 大きさ
• フォントの種類
• 配置
• 背景色
等
TextView の色の指定方法
• フォーマット
• 赤 (R) 緑 (G) 青 (B) に 16 進 2 桁( 00 ~ FF )
を使って色を表す。
• A は、透明度を表す。
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello“
android:textColor="#ff0000"
/>

專訪李光耀