Android Create Form Sign Up Image
1. Project Structure
2. Gradle
plugins {
id 'com.android.application'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.form.signupimage"
minSdkVersion 19
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'com.balysv:material-ripple:1.0.2'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'com.crystal:crystalrangeseekbar:1.1.3'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
3. Main Activity
package com.form.signupimage;
import android.content.DialogInterface;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import androidx.appcompat.widget.Toolbar;
import android.text.InputType;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import com.form.signupimage.utils.Tools;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_form_signup_image);
initToolbar();
initComponent();
}
private void initToolbar() {
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle(null);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Tools.setSystemBarColor(this, R.color.indigo_800);
}
private void initComponent() {
(findViewById(R.id.et_age)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showAgeDialog(v);
}
});
(findViewById(R.id.et_gender)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showGenderDialog(v);
}
});
(findViewById(R.id.et_country)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showCountryDialog(v);
}
});
(findViewById(R.id.bt_submit)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Submit", Toast.LENGTH_SHORT).show();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_setting, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
} else {
Toast.makeText(getApplicationContext(), item.getTitle(), Toast.LENGTH_SHORT).show();
}
return super.onOptionsItemSelected(item);
}
private void showAgeDialog(final View v) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Age");
final EditText input = new EditText(this);
input.setInputType(InputType.TYPE_CLASS_NUMBER);
builder.setView(input);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
((EditText) v).setText(input.getText().toString() + " " + "y.o");
}
});
builder.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builder.show();
}
private void showGenderDialog(final View v) {
final String[] array = new String[]{
"Male", "Female", "Other"
};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Age");
builder.setSingleChoiceItems(array, -1, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
((EditText) v).setText(array[i]);
dialogInterface.dismiss();
}
});
builder.show();
}
private void showCountryDialog(final View v) {
final String[] array = new String[]{
"United State", "Germany", "United Kingdom", "Australia"
};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Country");
builder.setSingleChoiceItems(array, -1, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
((EditText) v).setText(array[i]);
dialogInterface.dismiss();
}
});
builder.show();
}
}
4. Layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/image_30" />
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/indigo_800_overlay" />
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:fitsSystemWindows="false"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:contentInsetStartWithNavigation="0dp"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/toolbar"
android:clipToPadding="false"
android:padding="@dimen/spacing_mlarge"
android:scrollbars="none"
android:scrollingCache="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
style="@style/EditText.Flat.Grey"
android:layout_width="match_parent"
android:layout_height="@dimen/spacing_xmlarge"
android:layout_marginTop="@dimen/spacing_mlarge"
android:background="@drawable/edit_text_round_bg_overlay_white"
android:minHeight="@dimen/spacing_xmlarge"
android:paddingLeft="@dimen/spacing_middle"
android:paddingRight="@dimen/spacing_middle"
android:text="Roberts Turner"
android:textColor="@android:color/white" />
<EditText
style="@style/EditText.Flat.Grey"
android:layout_width="match_parent"
android:layout_height="@dimen/spacing_xmlarge"
android:layout_marginTop="@dimen/spacing_mlarge"
android:background="@drawable/edit_text_round_bg_overlay_white"
android:minHeight="@dimen/spacing_xmlarge"
android:paddingLeft="@dimen/spacing_middle"
android:paddingRight="@dimen/spacing_middle"
android:text="roberts.turner"
android:textColor="@android:color/white" />
<EditText
style="@style/EditText.Flat.Grey"
android:layout_width="match_parent"
android:layout_height="@dimen/spacing_xmlarge"
android:layout_marginTop="@dimen/spacing_mlarge"
android:background="@drawable/edit_text_round_bg_overlay_white"
android:minHeight="@dimen/spacing_xmlarge"
android:paddingLeft="@dimen/spacing_middle"
android:paddingRight="@dimen/spacing_middle"
android:text="******"
android:textColor="@android:color/white" />
<EditText
style="@style/EditText.Flat.Grey"
android:layout_width="match_parent"
android:layout_height="@dimen/spacing_xmlarge"
android:layout_marginTop="@dimen/spacing_mlarge"
android:background="@drawable/edit_text_round_bg_overlay_white"
android:minHeight="@dimen/spacing_xmlarge"
android:paddingLeft="@dimen/spacing_middle"
android:paddingRight="@dimen/spacing_middle"
android:text="roberts.turner@mail.com"
android:textColor="@android:color/white" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_mlarge"
android:orientation="horizontal">
<EditText
android:id="@+id/et_age"
style="@style/EditText.Flat.Grey"
android:layout_width="0dp"
android:layout_height="@dimen/spacing_xmlarge"
android:layout_weight="1"
android:background="@drawable/edit_text_round_bg_overlay_white"
android:drawableEnd="@drawable/ic_arrow_drop"
android:drawableRight="@drawable/ic_arrow_drop"
android:editable="false"
android:focusable="false"
android:minHeight="@dimen/spacing_xmlarge"
android:paddingLeft="@dimen/spacing_middle"
android:paddingRight="@dimen/spacing_middle"
android:text="29 y.o"
android:textColor="@android:color/white" />
<View
android:layout_width="@dimen/spacing_large"
android:layout_height="0dp" />
<EditText
android:id="@+id/et_gender"
style="@style/EditText.Flat.Grey"
android:layout_width="0dp"
android:layout_height="@dimen/spacing_xmlarge"
android:layout_weight="1"
android:background="@drawable/edit_text_round_bg_overlay_white"
android:drawableEnd="@drawable/ic_arrow_drop"
android:drawableRight="@drawable/ic_arrow_drop"
android:editable="false"
android:focusable="false"
android:minHeight="@dimen/spacing_xmlarge"
android:paddingLeft="@dimen/spacing_middle"
android:paddingRight="@dimen/spacing_middle"
android:text="Male"
android:textColor="@android:color/white" />
</LinearLayout>
<EditText
android:id="@+id/et_country"
style="@style/EditText.Flat.Grey"
android:layout_width="match_parent"
android:layout_height="@dimen/spacing_xmlarge"
android:layout_marginTop="@dimen/spacing_mlarge"
android:background="@drawable/edit_text_round_bg_overlay_white"
android:drawableEnd="@drawable/ic_arrow_drop"
android:drawableRight="@drawable/ic_arrow_drop"
android:editable="false"
android:focusable="false"
android:minHeight="@dimen/spacing_xmlarge"
android:paddingLeft="@dimen/spacing_middle"
android:paddingRight="@dimen/spacing_middle"
android:text="United State"
android:textColor="@android:color/white" />
<Button
android:id="@+id/bt_submit"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginLeft="-4dp"
android:layout_marginRight="-4dp"
android:layout_marginTop="@dimen/spacing_mlarge"
android:background="@drawable/btn_rect_white_overlay"
android:text="SUBMIT"
android:textAllCaps="false"
android:textAppearance="@style/TextAppearance.AppCompat.Body2"
android:textColor="@android:color/white" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</RelativeLayout>
5. Value
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:ns1="urn:oasis:names:tc:xliff:document:1.2">
<style name="ThemeOverlay.AppCompat.Dark.ActionBar" parent="Base.ThemeOverlay.AppCompat.Dark.ActionBar"/>
<style name="ThemeOverlay.AppCompat.Light" parent="Base.ThemeOverlay.AppCompat.Light"/>
<string name="appbar_scrolling_view_behavior" translatable="false">com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior</string>
<style name="TextAppearance.AppCompat.Body2" parent="Base.TextAppearance.AppCompat.Body2"/>
<style name="EditText.Flat.Grey" parent="@style/AppTheme">
<item name="android:textColorHint">@color/grey_40</item>
<item name="android:textAppearance">@style/Base.TextAppearance.AppCompat.Subhead</item>
<item name="android:textColor">@color/grey_90</item>
</style>
<string name="appbar_scrolling_view_behavior" translatable="false">com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior</string>
<color name="indigo_800_overlay">#E6283593</color>
</resources>