طراحی صفحه ثبت نام و لاگین جذاب اندروید

سلام با یک آموزش دیگه از سری آموزش های طراحی اندروید در خدمت شما هستم . توی این قسمت می خواهیم یک صفحه ی ثبت نام و ورود جذاب با استفاده از constraint layout بسازیم . صفحات لاگین تقریبا اولین صفحه ی هر اپلیکیشنی هست و باید جذاب و کاربر پسند باشد .
در این آموزش طراحی صفحه با فتوشاپ انجام گرفته و با استفاده از constraint layout به طراحی ui و قرارگیری ویدجت ها پرداخته شده .
اگر با constraint layout آشنایی ندارید حتما نگاهی به دوره ی مقدماتی اندروید و طراحی ui سایت بندازید .
برای آشنایی بیشتر با نحوه نوشتن کد ها و توضیحات دقیق تر می توانید ویدئوی آموزشی مرتبط به این بخش را مشاهده بفرمایید :
خروجی
قبل از همه چیز نگاهی به خروجی این آموزش بیندازیم
بخش فتوشاپ
فرض کنید چنین تصویری را بخش طراحی شرکت با فتوشاپ طراحی کرده و در اختیار شما قرار داده و از شما انتظار دارد دکمه ها را دقیقا در مکان تعبیه شده قرار دهید و شما هر کاری می کنید نمی توانید با استفاده از RelativeLayout و LinearLayout و سایر لیوت هایی که بلدید این طرح را طوری بر روی اپلیکیشن اعمال کنید که در هر گوشی با هر سایزی ، بدون تغییر در اختیار کاربر قرار گیرد .
تنها راهی که در حال حاضر وجود دارد استفاده از constraint layout است که به شما اجازه قراردهی اجزا به صورت دقیق بر روی صفحه می دهد .
ساخت یک پروژه جدید با نام SignUpApp
از طریق آدرس File–>New–>New Project در اندروید استودیو یک پروژه جدید بسازید و نام اپلیکیشن ، نام پکیج را نوشته ، زبان را جاوا انتخاب کنید ، در صفحه بعدی Empty activity را انتخاب کرده و سپس بر روی finish کلیک کرده تا پروژه شروع به ساخت کند .
اضافه کردن عکس بکگراند و لوگو به پروژه
عکس بکگراند هر صفحه را به صورت جداگانه با نرم افزار paint کراپ کنید و آن را با رعایت قوانین نامگذاری در پوشه ی mipmap قرار بدید .
عکس لوگو مورد نظر خود را نیز به همان صورت در اندروید استودیو قرار دهید.
ایجاد بکگراند با گوشه های گرد برای Button و EditText
بر روی پوشه ی drawable راست کلیک کرده و مسیر New–>Drawable resource file را طی نمایید .
نام فایل را بنویسید و بر روی OK کلیک کنید.
4 عدد Drawable resource file می سازیم که هر کدام وظیفه ی زیباسازی EditTextهای مناسب برای Email و Password و همینطور Button های Login و SignUp را دارند .
و باید این فایل ها را به عنوان ویژگی بکگراند به ویدجت های بر روی صفحه اضافه کنیم .
فایل بکگراند دکمه ی لاگین (Login (loginbuttonshape.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="#bd81f2"> </solid> <corners android:bottomLeftRadius="0dp" android:topLeftRadius="0dp" android:bottomRightRadius="25dp" android:topRightRadius="25dp"> </corners> </shape> |
اگر با shape و تگ های به کار رفته در آن آشنایی ندارید می توانید از دوره مقدماتی اندروید و ui استفاده نمایید.
فایل بکگراند دکمه ی ثبت نام (SignUp (signupbuttonshape.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="@android:color/white"> </solid> <corners android:bottomLeftRadius="0dp" android:topLeftRadius="0dp" android:bottomRightRadius="25dp" android:topRightRadius="25dp"> </corners> </shape> |
فایل بکگراند EditText
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="@android:color/white"> </solid> <corners android:bottomLeftRadius="5dp" android:topLeftRadius="5dp" android:bottomRightRadius="5dp" android:topRightRadius="5dp"> </corners> <padding android:top="10dp" android:bottom="10dp" android:left="10dp" android:right="10dp"> </padding> </shape> |
فایل بکگراند سایر Button ها
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="@android:color/white"> </solid> <corners android:bottomLeftRadius="25dp" android:topLeftRadius="25dp" android:bottomRightRadius="25dp" android:topRightRadius="25dp"> </corners> <stroke android:color="@android:color/holo_purple" android:width="1dp"> </stroke> </shape> |
طراحی صفحه ی activitymain.xml
فایل activitymain را باز کنید و این کد ها را وارد کنید .
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout 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="com.androidcodefinder.loginscreendemo.MainActivity" android:background="@mipmap/login"> <Button android:id="@+id/btnLogin" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="8dp" android:layout_marginEnd="8dp" android:layout_marginTop="8dp" android:background="@drawable/loginbuttonshape" android:text="Login" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.0" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.43" /> <Button android:id="@+id/btnSignup" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="8dp" android:layout_marginEnd="8dp" android:layout_marginTop="8dp" android:background="@drawable/signupbuttonshape" android:text="Signup" android:textColor="@android:color/black" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.0" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/btnLogin" app:layout_constraintVertical_bias="0.053" /> <ImageView android:id="@+id/imageView" android:layout_width="50dp" android:layout_height="50dp" android:layout_marginBottom="8dp" android:layout_marginEnd="8dp" android:layout_marginLeft="16dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.023" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/btnSignup" app:layout_constraintVertical_bias="0.05" app:srcCompat="@mipmap/facebook" /> <ImageView android:id="@+id/imageView2" android:layout_width="50dp" android:layout_height="50dp" android:layout_marginBottom="8dp" android:layout_marginEnd="8dp" android:layout_marginLeft="16dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.023" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/imageView" app:layout_constraintVertical_bias="0.021" app:srcCompat="@mipmap/google" /> <ImageView android:id="@+id/imageView3" android:layout_width="50dp" android:layout_height="50dp" android:layout_marginBottom="8dp" android:layout_marginEnd="8dp" android:layout_marginLeft="16dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.023" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/imageView2" app:layout_constraintVertical_bias="0.031" app:srcCompat="@mipmap/twitter" /> <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="8dp" android:layout_marginEnd="8dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" android:text="LOGO" android:textColor="@android:color/holo_purple" android:textSize="50dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.086" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.029" /> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="8dp" android:layout_marginEnd="16dp" android:layout_marginRight="16dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" android:text="Login" android:textSize="35dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.513" app:layout_constraintRight_toRightOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.216" /> <EditText android:id="@+id/editText" android:layout_width="wrap_content" android:layout_height="44dp" android:layout_marginBottom="8dp" android:layout_marginEnd="8dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" android:alpha="0.23" android:background="@drawable/textviewshape" android:ems="10" android:inputType="textPersonName" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.709" app:layout_constraintRight_toRightOf="parent" app:layout_constraintStart_toEndOf="@+id/btnLogin" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.427" /> <TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="8dp" android:layout_marginEnd="8dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" android:text="Email" app:layout_constraintBottom_toTopOf="@+id/editText" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.235" app:layout_constraintStart_toEndOf="@+id/btnLogin" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="1.0" /> <TextView android:id="@+id/textView4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="8dp" android:layout_marginEnd="8dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" android:text="Password" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.261" app:layout_constraintStart_toEndOf="@+id/btnSignup" app:layout_constraintTop_toBottomOf="@+id/editText" app:layout_constraintVertical_bias="0.094" /> <EditText android:id="@+id/editText2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="8dp" android:layout_marginEnd="8dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" android:alpha="0.23" android:background="@drawable/textviewshape" android:ems="10" android:inputType="textPersonName" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.688" app:layout_constraintStart_toEndOf="@+id/btnSignup" app:layout_constraintTop_toBottomOf="@+id/textView4" app:layout_constraintVertical_bias="0.003" /> <TextView android:id="@+id/textView5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="8dp" android:layout_marginEnd="8dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" android:text="ForgotPassword?" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.39" app:layout_constraintStart_toEndOf="@+id/imageView2" app:layout_constraintTop_toBottomOf="@+id/editText2" app:layout_constraintVertical_bias="0.152" /> <Button android:id="@+id/button3" android:layout_width="175dp" android:layout_height="wrap_content" android:layout_marginBottom="8dp" android:layout_marginEnd="8dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" android:background="@drawable/buttonshape" android:text="Login" android:textColor="@android:color/black" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.809" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.905" /> </android.support.constraint.ConstraintLayout> |
خروجی تا به الان به این شکل خواهد بود .
طراحی صفجه ی ثبت نام یا sign up
بر روی MainActivity.java راست کلیک کرده و مسیر New>Activity>EmptyActivity یک اکتیویتی جدید ساخته و نام کلاس آن را SignUpActivity و نام فایل layout آن را activity_signup.xml انتخاب کنید . کد های زیر را در فایل activity_signup.xml کپی کنید :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout 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="com.androidcodefinder.loginscreendemo.SignUpActivity" android:background="@mipmap/signup"> <Button android:id="@+id/btnLogin" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="8dp" android:layout_marginEnd="8dp" android:layout_marginTop="8dp" android:background="@drawable/signupbuttonshape" android:text="Login" android:textColor="@android:color/black" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.0" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.43" /> <Button android:id="@+id/btnSignup" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="8dp" android:layout_marginEnd="8dp" android:layout_marginTop="8dp" android:background="@drawable/loginbuttonshape" android:text="Signup" android:textColor="@android:color/white" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.0" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/btnLogin" app:layout_constraintVertical_bias="0.053" /> <ImageView android:id="@+id/imageView" android:layout_width="50dp" android:layout_height="50dp" android:layout_marginBottom="8dp" android:layout_marginEnd="8dp" android:layout_marginLeft="16dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.023" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/btnSignup" app:layout_constraintVertical_bias="0.05" app:srcCompat="@mipmap/facebook" /> <ImageView android:id="@+id/imageView2" android:layout_width="50dp" android:layout_height="50dp" android:layout_marginBottom="8dp" android:layout_marginEnd="8dp" android:layout_marginLeft="16dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.023" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/imageView" app:layout_constraintVertical_bias="0.021" app:srcCompat="@mipmap/google" /> <ImageView android:id="@+id/imageView3" android:layout_width="50dp" android:layout_height="50dp" android:layout_marginBottom="8dp" android:layout_marginEnd="8dp" android:layout_marginLeft="16dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.023" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/imageView2" app:layout_constraintVertical_bias="0.031" app:srcCompat="@mipmap/twitter" /> <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="8dp" android:layout_marginEnd="8dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" android:text="LOGO" android:textColor="@android:color/holo_purple" android:textSize="50dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.086" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.029" /> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="8dp" android:layout_marginEnd="16dp" android:layout_marginRight="16dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" android:text="Signup" android:textSize="35dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.513" app:layout_constraintRight_toRightOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.216" /> <EditText android:id="@+id/editText" android:layout_width="wrap_content" android:layout_height="44dp" android:layout_marginBottom="8dp" android:layout_marginEnd="8dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" android:alpha="0.23" android:background="@drawable/textviewshape" android:ems="10" android:inputType="textPersonName" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.709" app:layout_constraintRight_toRightOf="parent" app:layout_constraintStart_toEndOf="@+id/btnLogin" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.427" /> <TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="8dp" android:layout_marginEnd="8dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" android:text="Email" app:layout_constraintBottom_toTopOf="@+id/editText" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.235" app:layout_constraintStart_toEndOf="@+id/btnLogin" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="1.0" /> <TextView android:id="@+id/textView4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="8dp" android:layout_marginEnd="8dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" android:text="Password" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.261" app:layout_constraintStart_toEndOf="@+id/btnSignup" app:layout_constraintTop_toBottomOf="@+id/editText" app:layout_constraintVertical_bias="0.094" /> <EditText android:id="@+id/editText2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="8dp" android:layout_marginEnd="8dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" android:alpha="0.23" android:background="@drawable/textviewshape" android:ems="10" android:inputType="textPersonName" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.688" app:layout_constraintStart_toEndOf="@+id/btnSignup" app:layout_constraintTop_toBottomOf="@+id/textView4" app:layout_constraintVertical_bias="0.003" /> <TextView android:id="@+id/textView5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="8dp" android:layout_marginEnd="8dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" android:text="Confirm Password" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.405" app:layout_constraintStart_toEndOf="@+id/imageView2" app:layout_constraintTop_toBottomOf="@+id/editText2" app:layout_constraintVertical_bias="0.105" /> <Button android:id="@+id/button3" android:layout_width="175dp" android:layout_height="wrap_content" android:layout_marginBottom="8dp" android:layout_marginEnd="8dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" android:background="@drawable/buttonshape" android:text="Signup" android:textColor="@android:color/black" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.804" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.966" /> <EditText android:id="@+id/editText3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="8dp" android:layout_marginEnd="8dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" android:alpha="0.23" android:background="@drawable/textviewshape" android:ems="10" android:inputType="textPersonName" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.747" app:layout_constraintStart_toEndOf="@+id/imageView2" app:layout_constraintTop_toBottomOf="@+id/textView5" app:layout_constraintVertical_bias="0.0" /> </android.support.constraint.ConstraintLayout> |
جابه جایی بین دو اکتیویتی Login و SignUp
برای جابه جایی بین دو اکتیویتی از intent استفاده می کنیم .
MainActivity را باز کرده و بعد از پیدا کردن دکمه ی SignUp با متد findviewbyid و ست کردن عملیات کلیک بر روی آن ، با استفاده از intent وارد اکتیویتی SignUpActivity می شویم :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; public class MainActivity extends AppCompatActivity { private Button btnLogin,btnSignup; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btnLogin=(Button)findViewById(R.id.btnLogin); btnSignup=(Button)findViewById(R.id.btnSignup); btnSignup.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(MainActivity.this,SignUpActivity.class); startActivity(intent); } }); } } |
پس از تکمیل کد های MainActivity به صورت بالا ، فایل SignUpActivity را باز کرده و دقیقا همین عملیات را فقط این بار برای دکمه ی Login انجام می دهیم :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; public class SignUpActivity extends AppCompatActivity { private Button btnLogin,btnSignup; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sign_up); btnLogin=(Button)findViewById(R.id.btnLogin); btnSignup=(Button)findViewById(R.id.btnSignup); btnLogin.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(SignUpActivity.this,MainActivity.class); startActivity(intent); } }); } } |
که در نهایت خروجی پروژه شما باید به شکل زیر باشد :
مطالب زیر را حتما مطالعه کنید
نصب درایورهای هر گوشی برای اتصال به رایانه
اتصال گوشی به اندروید استودیو
دوره های آموزشی مرتبط
2 دیدگاه
به گفتگوی ما بپیوندید و دیدگاه خود را با ما در میان بگذارید.
I think it is a fluent sharing, I will recommend your site to my friends Vivianna Ephrayim Gagliano
Thanks for sharing your thoughts about meta_keyword. Regards| Modesty Cob Guinn