Android学習ノート——Button

3021 ワード

このプロジェクトの機能は、activityにTextViewとButtonを表示することです.
 
次のコードはMainActivityのコードです.
package com.example.button;



import android.app.Activity;

import android.os.Bundle;

import android.view.Menu;

import android.view.MenuItem;

import android.widget.Button;

import android.widget.TextView;



public class MainActivity extends Activity {



    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        TextView myTextView = (TextView)findViewById(R.id.myTextView);

        Button myButton = (Button)findViewById(R.id.myButton);

        myTextView.setText(" TextView");

        myButton.setText(" Button");

        

    }

}

 
次のコードはactivity_です.mainのコード
<RelativeLayout 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"

    tools:context="${relativePackage}.${activityClass}" >



    <TextView

        android:id="@+id/myTextView"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="@string/hello_world" />

    

    <Button

        android:id="@+id/myButton"

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        />



</RelativeLayout>