Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- activity_main.xml
- -----------------
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical"
- android:background="#00999F"
- android:id="@+id/llyBackground">
- <Button
- android:id="@+id/btnSayHello"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="say hello"
- android:textColor="#ff00ff"
- android:textSize="28sp"
- android:layout_margin="16dp"
- />
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal"
- android:layout_margin="16dp">
- <Button
- android:id="@+id/btnRed"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:text="Red" />
- <Button
- android:id="@+id/btnGreen"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:text="Green" />
- <Button
- android:id="@+id/btnBlue"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Blue"
- />
- </LinearLayout>
- <Button
- android:id="@+id/btnQuit"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_margin="16dp"
- android:text="quit"
- android:textColor="#0099ff"
- android:textSize="22sp" />
- <TextView
- android:id="@+id/tvText"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_margin="16dp"
- android:background="#009922"
- android:gravity="center"
- android:text="dogma" />
- </LinearLayout>
- MainActivity.java
- ------------------
- package com.example.mohamadpc.myfirstapplication;
- import android.graphics.Color;
- import android.os.Bundle;
- import android.support.v7.app.AppCompatActivity;
- import android.view.View;
- import android.widget.Button;
- import android.widget.TextView;
- public class MainActivity extends AppCompatActivity implements View.OnClickListener {
- Button b1, b2;
- TextView text1;
- Button btnRed, btnBlue, btnGreen;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- b1 = (Button) findViewById(R.id.btnSayHello);
- b2 = (Button) findViewById(R.id.btnQuit);
- text1 = (TextView) findViewById(R.id.tvText);
- btnRed = (Button) findViewById(R.id.btnRed);
- btnGreen = (Button) findViewById(R.id.btnGreen);
- btnBlue = (Button) findViewById(R.id.btnBlue);
- b1.setOnClickListener(this);
- b2.setOnClickListener(this);
- text1.setOnClickListener(this);
- btnRed.setOnClickListener(this);
- btnGreen.setOnClickListener(this);
- btnBlue.setOnClickListener(this);
- findViewById(R.id.llyBackground).setBackgroundColor(Color.YELLOW);
- }
- @Override
- public void onClick(View v) {
- switch (v.getId()) {
- case R.id.btnSayHello:
- text1.setText("Welcome to android");
- text1.setTextSize(10);
- break;
- case R.id.btnQuit:
- this.finish();
- break;
- case R.id.tvText:
- text1.setTextSize(text1.getTextSize() + 1);
- break;
- case R.id.btnBlue:
- text1.setBackgroundColor(Color.BLUE);
- text1.setTextColor(Color.WHITE);
- break;
- case R.id.btnRed:
- text1.setBackgroundColor(Color.RED);
- text1.setTextColor(Color.YELLOW);
- break;
- case R.id.btnGreen:
- text1.setBackgroundColor(Color.GREEN);
- text1.setTextColor(Color.BLUE);
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement