0% found this document useful (0 votes)
75 views8 pages

Android App XML and Java Code Structure

The document contains XML code for styles, strings, layouts and the Android manifest file for an Android application. The styles section defines the theme and colors for the app. The strings section contains text values like the app name. The layout sections contain code for the splash screen, login, register and other activity screens. The manifest declares app components and permissions. The Java code shows splash and register activities that launch intents and handle basic validation.

Uploaded by

Icha Riza Avisha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views8 pages

Android App XML and Java Code Structure

The document contains XML code for styles, strings, layouts and the Android manifest file for an Android application. The styles section defines the theme and colors for the app. The strings section contains text values like the app name. The layout sections contain code for the splash screen, login, register and other activity screens. The manifest declares app components and permissions. The Java code shows splash and register activities that launch intents and handle basic validation.

Uploaded by

Icha Riza Avisha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

VALUES XML

STYLE
<resources>

<!-- Base application theme. -->


<style name="AppTheme" parent="[Link]">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="SplashSukaSuka" parent="[Link]">

</style>

</resources>

STRING
<resources>
<string name="app_name">My</string>

<string-array name="kota">
<item></item>
<item>Jakarta</item>
<item>Bandung</item>
<item>Yogyakarta</item>
<item>Surabaya</item>
</string-array>

</resources>

LAYOUT XML

SPLASH ACTIVITY
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#14141D"
tools:context=".SplashActivity">

<ImageView
android:src="@drawable/logoku"
android:layout_gravity="center"
android:layout_width="200dp"
android:layout_height="200dp" />

</FrameLayout>
LOGIN ACTIVITY
<?xml version="1.0" encoding="utf-8"?><!-- -->
<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:orientation="horizontal">

<TextView
android:layout_width="80dp"
android:layout_height="wrap_content"
android:text="Email"/>

<EditText
android:id="@+id/E1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress" />

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:orientation="horizontal">

<TextView
android:layout_width="80dp"
android:layout_height="wrap_content"
android:text="Password" />

<EditText
android:id="@+id/E2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword" />

</LinearLayout>

<TextView
android:gravity="center"
android:id="@+id/daftar"
android:textColor="#3F51B5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Daftar Baru"
android:onClick="Daftar_Id"/>

<Button
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:drawableLeft="@drawable/ic_snowandrainatnight_119731"
android:onClick="Button_Login"
android:text="Login"
android:textColor="#FFFFFF"
android:textStyle="bold" />

</LinearLayout>

REGISTER ACTIVITY
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="[Link]

<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".RegisterActivity">

<EditText
android:id="@+id/E1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Nama"
android:maxLength="50" />

<EditText
android:id="@+id/E2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Email"
android:inputType="textEmailAddress" />

<EditText
android:id="@+id/E3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword" />

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Phone"
android:inputType="phone"
android:maxLength="12" />

<ImageView
android:id="@+id/img"
android:layout_width="200dp"
android:layout_height="200dp" />

<TextView
android:text="Camera"
android:layout_gravity="left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="OpenCamera"/>

<Spinner
android:id="@+id/S1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="@array/kota"
android:spinnerMode="dialog"></Spinner>

<DatePicker
android:id="@+id/Dt1"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:datePickerMode="calendar"></DatePicker>

<TimePicker
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:timePickerMode="spinner"></TimePicker>

<RatingBar
android:layout_gravity="center"
android:numStars="5"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<Button
android:text="Save"
android:drawableLeft="@drawable/ic_snowandrainatnight_119731"
android:layout_gravity="center"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:onClick="Terserah"/>

</LinearLayout>
</ScrollView>

MANIFEST
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="[Link]
package="[Link]">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".HomeActivity"></activity>
<activity
android:name=".SplashActivity"
android:screenOrientation="portrait"
android:theme="@style/SplashSukaSuka">
<intent-filter>
<action android:name="[Link]" />
<category android:name="[Link]" />
</intent-filter>
</activity>
<activity android:name=".RegisterActivity" />
<activity android:name=".RelativeActivity" />
<activity android:name=".FrameActivity" />
<activity android:name=".MainActivity" />
</application>

</manifest>

JAVA

SPLASH
package [Link];

import [Link];
import [Link];
import [Link];
import [Link];

public class SplashActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_splash);

Handler h = new Handler();


[Link](new Runnable() {
@Override
public void run() {
Intent balik = new Intent(getApplicationContext(),[Link]);
startActivity(balik);
finish();
}
}, 2000);
}
}

REGISTER
package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class RegisterActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_register);
}

public void Terserah(View view) {


//validasi nama dll tidak boleh kosong
EditText E1 = (EditText) findViewById([Link].E1);
EditText E2 = (EditText) findViewById([Link].E2);
EditText E3 = (EditText) findViewById([Link].E3);
Spinner S1 = (Spinner) findViewById([Link].S1);
DatePicker Dt1 = (DatePicker) findViewById([Link].Dt1);

//semua yang dari EditText pasti "toString"

// boolean isicheckbox = [Link]();


//if (isicheckbox = false){toast lagi}

String a = [Link]().toString();
String b = [Link]().toString();
String c = [Link]().toString();
String d = [Link]().toString();
int tanggal = [Link]();
int bulan = [Link]();
int tahun = [Link]();

if ([Link]() == 0)
{
[Link](getApplicationContext(), "Name harus di isi",
Toast.LENGTH_SHORT).show();
return;
}

else if ([Link]() < 5)


{
[Link]("Email minimal 5 karakter");
return;
}

if ([Link]() == 0)
{
[Link](getApplicationContext(), "Email harus di isi",
Toast.LENGTH_SHORT).show();
[Link]();
return;

if(Patterns.EMAIL_ADDRESS.matcher(b).matches() == false)
{
[Link]("Email Salah");
[Link]();
return;
}

if ([Link]() < 6)
{
[Link]("Karakter Password Kurang dari 6 karakter");
[Link]();
return;
}

//dijalankan ketika di klik


[Link](getApplicationContext(), "Success", Toast.LENGTH_LONG).show();

Intent balik = new Intent(getApplicationContext(),[Link]);


startActivity(balik);
}

@Override //ketik aj onActivityResult dan km tab aj.. harus d atas OpenCamera


protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent
data) {
[Link](requestCode, resultCode, data);

if(requestCode == 123)
{
if(resultCode == RESULT_OK)
{
ImageView img = (ImageView) findViewById([Link]);

Bitmap gambarnya = (Bitmap) [Link]().get("data");


[Link](gambarnya);// "img" itu id ImageView nya di XML

}
}

public void OpenCamera(View view) {


Intent balik = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(balik, 123); //angka nya terserah dan brp aj 32000
}
}

HOME
package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class HomeActivity extends AppCompatActivity {

@Override
public boolean onOptionsItemSelected(MenuItem item) //koding ini untuk menjalan
kan option menu ketika d klik
{
if([Link]() == [Link])
{

}
else if([Link]() == [Link])
{
[Link](getApplicationContext(), "Program created by Dee",
Toast.LENGTH_SHORT).show();
}
else if([Link]() == [Link])
{
Intent balik = new Intent(getApplicationContext(), [Link]);
startActivity(balik);
finish();
}
if([Link]() == [Link])
{
finishAffinity();
}
return [Link](item);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) //koding ini untuk menampilkan
option menu
{
getMenuInflater().inflate([Link].top_right_menu, menu);

return [Link](menu);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_home);

//ambil kirim1

String email = getIntent().getStringExtra("kirim1");

[Link](getApplicationContext(),"Welcome " + email,


Toast.LENGTH_SHORT).show();
}
}

Common questions

Powered by AI

Error feedback is provided through `EditText` error prompts and `Toast` messages during the registration process. For instance, if the email is invalid or the password is insufficient, respective fields show error messages and focus is requested. This immediate feedback mechanism enhances user experience by clearly indicating input mistakes, guiding users to correct them promptly, thus improving form completion rates .

In `RegisterActivity`, validation checks include ensuring the name field is not empty and contains at least 5 characters, verifying that the email field is not empty and contains a valid email pattern, and checking that the password is at least 6 characters long. Users receive feedback via toast messages and `EditText` error prompts if these conditions are not met .

Using `finishAffinity()` in the option menu of `HomeActivity` is significant as it closes all activities in the task stack of the current task, effectively exiting the application. This method ensures the app terminates completely, rather than returning to a previous activity .

The role of the `DatePicker` component in `RegisterActivity` is to allow the user to select a date, which is necessary for the registration process. It is integrated into the layout with attributes such as `android:id="@+id/Dt1"`, `android:layout_gravity="center"`, and `android:datePickerMode="calendar"`, making it versatile for user input .

The `OpenCamera` method in `RegisterActivity` uses an `Intent` with `MediaStore.ACTION_IMAGE_CAPTURE` to initiate the camera app. It then calls `startActivityForResult` to capture a photo, which handles the result in `onActivityResult` where the captured image is processed and displayed in an `ImageView` using `setImageBitmap` .

The transition from `SplashActivity` to `MainActivity` is implemented using a `Handler` and `Runnable`. A delay of 2000 milliseconds is set through `postDelayed`, after which an `Intent` is created to start `MainActivity`, and `finish()` is called to remove `SplashActivity` from the back stack .

The application icon is set using the `android:icon` attribute in the `<application>` tag of the `AndroidManifest.xml`. It is specified as `@mipmap/ic_launcher`, which points to the drawable resource for the icon. The purpose of setting an application icon is to provide a visual identifier for the app on the device's launcher and app-switch screen .

The application ensures that `SplashActivity` always launches in portrait orientation by setting the `android:screenOrientation` attribute to `portrait` in the `AndroidManifest.xml` under the `<activity>` element for `SplashActivity` .

The `AppTheme` style customizes the application's appearance by specifying color resources for `colorPrimary`, `colorPrimaryDark`, and `colorAccent`. These resources are defined as `@color/colorPrimary`, `@color/colorPrimaryDark`, and `@color/colorAccent`, respectively .

The spinner component within `RegisterActivity` is used to allow users to select from predefined options. It uses the string-array `@array/kota` which contains city names such as `Jakarta`, `Bandung`, `Yogyakarta`, and `Surabaya`. This enhances user interaction by providing a drop-down list to select a city .

You might also like