From 05ee8098c65f562915ec395936eeb801ab44f2a7 Mon Sep 17 00:00:00 2001 From: romadebrian Date: Mon, 10 Jan 2022 19:58:58 +0700 Subject: [PATCH] Color background tint --- .../roma/kalkulatorpersen/MainActivity.java | 79 +++++++++++++------ app/src/main/res/layout/activity_main.xml | 20 +++-- app/src/main/res/layout/persen_1.xml | 15 ++-- app/src/main/res/layout/persen_2.xml | 15 ++-- 4 files changed, 86 insertions(+), 43 deletions(-) diff --git a/app/src/main/java/com/roma/kalkulatorpersen/MainActivity.java b/app/src/main/java/com/roma/kalkulatorpersen/MainActivity.java index a8d6568..e791370 100644 --- a/app/src/main/java/com/roma/kalkulatorpersen/MainActivity.java +++ b/app/src/main/java/com/roma/kalkulatorpersen/MainActivity.java @@ -2,18 +2,21 @@ import androidx.appcompat.app.AppCompatActivity; +import android.graphics.Color; import android.os.Bundle; import android.renderscript.Script; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.EditText; +import android.widget.ImageView; import android.widget.Toast; public class MainActivity extends AppCompatActivity { View Form1; EditText Jumlah, Persen, Hasil, Jumlah2, Berapa, Hasil2; Button Hitung, Hitung2, Mode1, Mode2; + ImageView Footer; @Override @@ -35,34 +38,36 @@ protected void onCreate(Bundle savedInstanceState) { Hasil2 = findViewById(R.id.Frm_Input_Hasil2); Hitung2 = findViewById(R.id.Frm_Btn_Hitung2); + Footer = findViewById(R.id.Frm_Img_Footer); -// Hitung.setOnClickListener(new View.OnClickListener() { -// @Override -// public void onClick(View view) { -// String input1 = Jumlah.getText().toString(); -// String input2 = Persen.getText().toString(); -// -// if (input1.length() == 0) { -// Toast.makeText(MainActivity.this, "Jumlah Tidak Boleh Kosong", Toast.LENGTH_SHORT).show(); -// return; -// } -// else if (input2.length() == 0) { -// Toast.makeText(MainActivity.this, "Persen Tidak Boleh Kosong", Toast.LENGTH_SHORT).show(); -// return; -// } -// else { -// int jumlah = Integer.parseInt(input1); -// int persen = Integer.parseInt(input2); -// -// int hasil = jumlah * persen / 100; -// -// Hasil.setText(String.valueOf(hasil)); -// Log.d( "Hasilnya: ", String.valueOf(hasil)); -// } -// -// } -// }); + + Hitung.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + String input1 = Jumlah.getText().toString(); + String input2 = Persen.getText().toString(); + + if (input1.length() == 0) { + Toast.makeText(MainActivity.this, "Jumlah Tidak Boleh Kosong", Toast.LENGTH_SHORT).show(); + return; + } + else if (input2.length() == 0) { + Toast.makeText(MainActivity.this, "Persen Tidak Boleh Kosong", Toast.LENGTH_SHORT).show(); + return; + } + else { + int jumlah = Integer.parseInt(input1); + int persen = Integer.parseInt(input2); + + int hasil = jumlah * persen / 100; + + Hasil.setText(String.valueOf(hasil)); + Log.d( "Hasilnya: ", String.valueOf(hasil)); + } + + } + }); Hitung2.setOnClickListener(new View.OnClickListener() { @Override @@ -90,9 +95,31 @@ public void onClick(View v) { }); Mode1.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + findViewById(R.id.Frm_Include).setVisibility(View.VISIBLE); + findViewById(R.id.Frm_Include2).setVisibility(View.GONE); + + Mode1.setBackgroundColor(Color.parseColor("#018786")); + Mode2.setBackgroundColor(Color.parseColor("#6200EE")); + } + }); + + Mode2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { findViewById(R.id.Frm_Include).setVisibility(View.GONE); + findViewById(R.id.Frm_Include2).setVisibility(View.VISIBLE); + + Mode1.setBackgroundColor(Color.parseColor("#6200EE")); + Mode2.setBackgroundColor(Color.parseColor("#018786")); + } + }); + + Footer.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Toast.makeText(MainActivity.this, "Created by Roma Debrian", Toast.LENGTH_SHORT).show(); } }); } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 786ce0e..cdf97ce 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -12,7 +12,7 @@ + android:background="@color/white" + android:orientation="vertical"> + layout="@layout/persen_1" + android:visibility="visible"/> + + @@ -48,9 +49,10 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" - android:minHeight="48dp" + android:backgroundTint="#4CAF50" + android:hint="5" android:inputType="number" - android:hint="0" + android:minHeight="48dp" android:textColor="@color/black" android:textSize="16sp" /> @@ -79,9 +81,10 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" - android:minHeight="48dp" + android:backgroundTint="#4CAF50" + android:hint="50" android:inputType="number" - android:hint="0" + android:minHeight="48dp" android:textColor="@color/black" android:textSize="16sp" /> diff --git a/app/src/main/res/layout/persen_2.xml b/app/src/main/res/layout/persen_2.xml index d668834..5efee54 100644 --- a/app/src/main/res/layout/persen_2.xml +++ b/app/src/main/res/layout/persen_2.xml @@ -23,9 +23,10 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" - android:minHeight="48dp" - android:inputType="number" + android:backgroundTint="#4CAF50" android:hint="0" + android:inputType="number" + android:minHeight="48dp" android:textColor="@color/black" android:textSize="16sp" /> @@ -48,9 +49,10 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" - android:minHeight="48dp" - android:inputType="number" + android:backgroundTint="#4CAF50" android:hint="0" + android:inputType="number" + android:minHeight="48dp" android:textColor="@color/black" android:textSize="16sp" /> @@ -79,9 +81,10 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" - android:minHeight="48dp" - android:inputType="number" + android:backgroundTint="#4CAF50" android:hint="0" + android:inputType="number" + android:minHeight="48dp" android:textColor="@color/black" android:textSize="16sp" />