mmayoub

School, class work 05.11.2017

Nov 5th, 2017
126
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. activity_main.xml
  2. ------------------
  3. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  4.     android:id="@+id/llyBack"
  5.     android:layout_width="match_parent"
  6.     android:layout_height="match_parent"
  7.     android:orientation="vertical">
  8.  
  9.     xmlns:android="http://schemas.android.com/apk/res/android" >
  10.  
  11.     <TextView
  12.         android:id="@+id/tvHello"
  13.         android:layout_width="match_parent"
  14.         android:layout_height="wrap_content"
  15.         android:background="@color/colorAccent"
  16.         android:gravity="center"
  17.         android:text="Hello"
  18.         android:textSize="32sp" />
  19.  
  20.     <EditText
  21.         android:id="@+id/etName"
  22.         android:layout_width="match_parent"
  23.         android:layout_height="wrap_content"
  24.         android:layout_margin="16dp"
  25.         android:hint="Enter your name"
  26.         android:textSize="26sp" />
  27.  
  28.     <Button
  29.         android:id="@+id/btClick"
  30.         android:layout_width="match_parent"
  31.         android:layout_height="wrap_content"
  32.         android:layout_margin="16dp"
  33.         android:text="Click Here"
  34.         android:textSize="24sp" />
  35. </LinearLayout>
  36.  
  37. MainActivity.java
  38. -----------------
  39. package com.example.mohamadpc.myapplication;
  40.  
  41. import android.app.Activity;
  42. import android.graphics.Color;
  43. import android.support.v7.app.AppCompatActivity;
  44. import android.os.Bundle;
  45. import android.view.View;
  46. import android.widget.Button;
  47. import android.widget.EditText;
  48. import android.widget.LinearLayout;
  49. import android.widget.TextView;
  50. import android.widget.Toast;
  51.  
  52. public class MainActivity extends Activity implements View.OnClickListener {
  53.     LinearLayout llyBack;
  54.     TextView tvHello;
  55.     EditText etName;
  56.     Button btClick;
  57.  
  58.     @Override
  59.     protected void onCreate(Bundle savedInstanceState) {
  60.         super.onCreate(savedInstanceState);
  61.         setContentView(R.layout.activity_main);
  62.  
  63.         llyBack = findViewById(R.id.llyBack);
  64.         tvHello = findViewById(R.id.tvHello);
  65.         etName = findViewById(R.id.etName);
  66.         btClick = findViewById(R.id.btClick);
  67.  
  68.         llyBack.setBackgroundColor(Color.GREEN);
  69.         tvHello.setText("Go Home");
  70.         btClick.setText("Login");
  71.         btClick.setOnClickListener(this);
  72.     }
  73.  
  74.     @Override
  75.     public void onClick(View v) {
  76.         Toast.makeText(this, "Welcome " + etName.getText(), Toast.LENGTH_LONG).show();
  77.     }
  78. }
RAW Paste Data