Lompat ke konten Lompat ke sidebar Lompat ke footer

Code Login Sederhana (Android Studio)

Oke kini aku akan membagikan cara untuk menciptakan login sederhana.
 
pertama kau masukan dibawah arahan untuk 
 
 


activity layoutnya :

 

<RelativeLayout     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"     android:background="#5fb0c9">      <TextView         android:id="@+id/login_title"         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:layout_marginBottom="16dp"         android:layout_marginTop="22dp"         android:gravity="center"         android:text="@string/account_login"         android:textColor="#fff"         android:textSize="26sp"         android:textStyle="bold" />      <LinearLayout         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:layout_below="@+id/login_title"         android:layout_marginLeft="30dp"         android:layout_marginRight="30dp"         android:layout_marginTop="70dp"         android:background="#fff"         android:padding="20dp"         android:orientation="vertical">          <LinearLayout             android:layout_width="fill_parent"             android:layout_height="wrap_content"             android:orientation="vertical"             android:paddingTop="30dp">              <EditText                 android:id="@+id/username"                 android:layout_width="fill_parent"                 android:layout_height="wrap_content"                 android:singleLine="true"                 android:hint="@string/user_name"                 android:inputTyzpe="textEmailAddress" />              <EditText                 android:id="@+id/password"                 android:layout_width="fill_parent"                 android:layout_height="wrap_content"                 android:layout_marginTop="16dp"                 android:singleLine="true"                 android:hint="@string/password"                 android:inputType="textPassword"/>              <TextView                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_gravity="right"                 android:paddingTop="5dp"                 android:text="@string/forgot_password"                 tools:ignore="RtlHardcoded" />               <Button                 android:layout_width="fill_parent"                 android:layout_height="wrap_content"                 android:layout_margin="22dp"                 android:background="#d67601"                 android:text="@string/sign_in"                 android:textAllCaps="false"                 android:textColor="#fff"                 android:textSize="18sp"                 android:onClick="ButtonLogin"/>         </LinearLayout>     </LinearLayout>      <ImageView         android:id="@+id/imageView"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_below="@+id/login_title"         android:paddingTop="35dp"         android:layout_centerHorizontal="true"         app:srcCompat="@mipmap/ic_launcher_round"         tools:ignore="ContentDescription" />  </RelativeLayout>
 

untuk class activity_login :

import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.EditText; import android.widget.Toast;  public class LoginActivity extends AppCompatActivity{      public static selesai String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";     public static selesai String EXTRA_MESSAGE2 = "com.example.myfirstapp.MESSAGE2";      @Override    protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_login);     }      public void ButtonLogin(View view){         Toast.makeText(this, "Login Bro!", Toast.LENGTH_SHORT).show();         EditText editText = (EditText) findViewById(R.id.username);         String message = editText.getText().toString();         EditText editText2 = (EditText) findViewById(R.id.password);         String message2 = editText2.getText().toString();          if(message.equals("saya")&&message2.equals("test")){              Intent intent = new Intent(this, MainActivity.class);             intent.putExtra(EXTRA_MESSAGE, message);             intent.putExtra(EXTRA_MESSAGE2, message2);             startActivity(intent);         }       } }
 

activity Main :

import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.TextView;  public class MainActivity extends AppCompatActivity {      @Override    protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_main);          // Get the Intent that started this activity and extract the string        Intent intent = getIntent();         String message = intent.getStringExtra(LoginActivity.EXTRA_MESSAGE);          // Capture the layout's TextView and set the string as its text        TextView textView = findViewById(R.id.title_main);         textView.setText("WELCOME "+message);     } }
 
 
 
untuk penerapan dapat lihat vidio dibawah: