TextView
MainActivity.java
package com.example.sasakiakira.uisample2;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
/** Button. */
private Button mButton01;
/** TextView. */
private TextView mTextView01;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mButton01 = (Button) findViewById(R.id.button01);
mButton01.setOnClickListener(this);
mTextView01 = (TextView) findViewById(R.id.textView01);
}
@Override
public void onClick(View v) {
if (v.equals(mButton01)) {
mTextView01.setText("Button Clicked");
}
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<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" 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">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TEST"
android:textSize="50px"
android:id="@+id/textView01"
android:textColor="#ffffff"
android:background="#000000"
android:layout_centerHorizontal="true" />
<Button
android:id="@+id/button01"
android:text="buttonSample1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/button_anim"
android:layout_below="@+id/textView1"
>
</Button>
</RelativeLayout>