andoid - TeachMeSoft

andoid






activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:orientation="vertical">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Mengambil Nilai dari Edit Text"
        android:layout_marginTop="20dp"
        android:layout_marginLeft="35dp"
        android:textStyle="bold"
        android:textColor="#000000"
        android:background="#FFC0CB"
        android:textSize="24sp"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Nama:"
        android:textStyle="bold"
        android:textColor="#000000"
        android:textSize="24sp"/>

    <EditText
        android:id="@+id/edit1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:hint="Masukan Nama ..."
        android:textSize="24sp"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="NIM:"
        android:textStyle="bold"
        android:textColor="#000000"
        android:textSize="24sp"/>

    <EditText
        android:id="@+id/edit2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:hint="Masukan NIM ..."
        android:textSize="24sp"/>

    <Button
        android:id="@+id/btnProcess"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="onProcess"
        android:text="Process"
        android:layout_gravity="right"
        android:textColor="@android:color/white"
        android:theme="@style/AppTheme" />

    <TextView
        android:id="@+id/hasil"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="24sp"
        android:textStyle="bold"
        android:textColor="#000000"
        android:layout_gravity="center"
        android:text="Nama " />
    <TextView
        android:id="@+id/hasil2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="24sp"
        android:textStyle="bold"
        android:textColor="#000000"
        android:layout_gravity="center"
        android:text="Nim" />

</LinearLayout>

MainActivity.java
package com.example.datamahasiswa;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    EditText edPesan1, edPesan2;
    TextView textPesan1, textPesan2;
    String pesan1, pesan2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        edPesan1 = (EditText) findViewById(R.id.edit1);
        edPesan2 = (EditText) findViewById(R.id.edit2);
        textPesan1 = (TextView) findViewById(R.id.hasil);
        textPesan2 = (TextView) findViewById(R.id.hasil2);
    }

    public void onProcess (View view){
        pesan1 = String.valueOf(edPesan1.getText());
        textPesan1.setText(pesan1);

        pesan2 = String.valueOf(edPesan2.getText());
        textPesan2.setText(pesan2);
    }
}



style.xml
<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="colorControlHighlight">@color/orange</item>
        <item name="colorButtonNormal">@color/green</item>
    </style>

</resources>



color.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#6200EE</color>
    <color name="colorPrimaryDark">#3700B3</color>
    <color name="colorAccent">#03DAC5</color>
    <color name="orange">#FFA500 </color>
    <color name="green">#2F4F4F</color>
</resources>




Disqus comments