AndroidDevelopersのチュートリアルのHelloFormStuffのCustomButtonを実行します。
【手順】
1.「Androidプロジェクトの作成方法」の手順で、「AndroidSample014-HelloFormStuffCustomButton」といプロジェクトを作成。
※プロジェクトの設定は以下の通り。
4.「任意のファイルの作成方法」の手順で、「res/drawable/」ディレクトリに「android_button.xml」というファイルを作成。
5.「res/drawable/android_button.xml」を以下の様に入力。
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/android_pressed" android:state_pressed="true"/>
<item android:drawable="@drawable/android_focused" android:state_focused="true"/>
<item android:drawable="@drawable/android_normal"/>
</selector>
6.「res/layout/main.xml」を以下の様に入力。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/android_button"
android:onClick="onButtonClicked"
android:padding="10dp" />
</LinearLayout>
7.「Ctrl+Shift+F」を押し、ソースコードをフォーマッティング。
8.「HelloFormStuffCustomButton.java」を以下の様に入力。
package com.example.androidsample014;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
public class HelloFormStuffCustomButton extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void onButtonClicked(View v) {
// Do something when the button is clicked
Toast.makeText(HelloFormStuffCustomButton.this, "Button clicked",
Toast.LENGTH_SHORT).show();
}
}
9.「Ctrl+Shift+F」を押し、ソースコードをフォーマッティング。10.「Androidプロジェクトの実行方法」の手順で、「Androidプロジェクト」を実行。11.エミュレータが起動しロックを解除し、以下の様にアプリケーションが実行されれば成功です。
以上です。
HelloFormStuff+CustomButton-01.png)
HelloFormStuff+CustomButton-02.png)
HelloFormStuff+CustomButton-03.png)
0 件のコメント:
コメントを投稿
注: コメントを投稿できるのは、このブログのメンバーだけです。