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:id="@+id/llyBack"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical">
- xmlns:android="http://schemas.android.com/apk/res/android" >
- <TextView
- android:id="@+id/tvHello"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:background="@color/colorAccent"
- android:gravity="center"
- android:text="Hello"
- android:textSize="32sp" />
- <EditText
- android:id="@+id/etName"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_margin="16dp"
- android:hint="Enter your name"
- android:textSize="26sp" />
- <Button
- android:id="@+id/btClick"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_margin="16dp"
- android:text="Click Here"
- android:textSize="24sp" />
- </LinearLayout>
- MainActivity.java
- -----------------
- package com.example.mohamadpc.myapplication;
- import android.app.Activity;
- import android.graphics.Color;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.LinearLayout;
- import android.widget.TextView;
- import android.widget.Toast;
- public class MainActivity extends Activity implements View.OnClickListener {
- LinearLayout llyBack;
- TextView tvHello;
- EditText etName;
- Button btClick;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- llyBack = findViewById(R.id.llyBack);
- tvHello = findViewById(R.id.tvHello);
- etName = findViewById(R.id.etName);
- btClick = findViewById(R.id.btClick);
- llyBack.setBackgroundColor(Color.GREEN);
- tvHello.setText("Go Home");
- btClick.setText("Login");
- btClick.setOnClickListener(this);
- }
- @Override
- public void onClick(View v) {
- Toast.makeText(this, "Welcome " + etName.getText(), Toast.LENGTH_LONG).show();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement