افزودن دکمه ها
در مرحله آن گاه، دو دکمه را به برگه ورود خویش اضافه میکنیم: « Cancel » و طراحی اپلیکیشن در مشهد « Next ».
ما از مولفه MDC Button به کار گیری خواهیم کرد که با یک استایل موج دار جوهری Material Design دکمه ها را اضافه می نماید .
در shr_login_fragment.xml، یک را به ، در تحت عنصرها TextInputLayout اضافه نمائید.
آنگاه دو عنصر را به اضافه فرمائید.
پوشه XML نتایج بایستی به صورت پایین باشد:
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:id="@+id/next_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:text="@string/shr_button_next" />
android:id="@+id/cancel_button"
style="@style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="12dp"
android:layout_marginRight="12dp"
android:layout_toStartOf="@id/next_button"
android:layout_toLeftOf="@id/next_button"
android:text="@string/shr_button_cancel" />
اکنون میبینید زمانی که نرمافزار را انجام میکنید، با ضربه زدن روی هر دکمه، یک موج جوهر نشان داده میشود.
رفتن به بخش آجل
در غایت، کد جاوا را به LoginFragment.java اضافه میکنیم تا دکمه “NEXT” خویش را به قطعه دیگری متصل کنیم.
متوجه خواهید شد که هرکدام از مؤلفه هایی که به طرح خویش اضافه کردیم، یک شناسه به آن تخصیص داده گردیده است.
ما از این شناسهها برای ارجاع به مؤلفههای کدمان به کار گیری می کنیم و برخی از قابلیت و امکان ها مانند تحقیق ایرادات و پیمایش را اضافه می کنیم.
بیایید یک اسلوب بولی سری isPasswordValid در LoginFragment.java در پایین () onCreateView اضافه کنیم که منطقی برای گزینش اینکه آیا سر عبور دارای اعتبار میباشد یا این که خیرمی باشد.
برای هدف ها این دمو، ما صرفا مطمئن می شویم که راز عبور دست کم 8 کاراکتر باشد:
/*
In reality, this will have more complex logic including, but not limited to, actual
authentication of the username and password.
*/
private boolean isPasswordValid(@Nullable Editable text) {
return text != null && text.length() >= 8;
}
در مرحله بعد از آن، یک کلیک listener به دکمه « NEXT» اضافه نمایید که غلط را مبتنی بر روال () isPasswordValid که ساخت و ساز کردیم تهیه و تنظیم و منزه می نماید.
در () onCreateView، این کلیک listener می بایست میان خط inflater و خط نمای بازگشتی قرار گیرد.
در مرحله سپس، بیایید یک listener کلیدی به سر عبور TextInputEditText اضافه کنیم تا به رویدادهای کلیدی که غلط را تمیز می نمایند اعتنا داشته باشیم.
این listener همینطور بایستی از () isPasswordValid برای پژوهش دارای اعتبار بودن یا این که نبودن راز عبور به کار گیری نماید.
میتوانید این گزینه را مستقیماً ذیل کلیک مستمع در () onCreateView اضافه نمائید.
سیاق onCreateView شما در حال حاضر بایستی چیزی مشابه بهاین باشد:
@Override
public View onCreateView(
@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.shr_login_fragment, container, false);
final TextInputLayout passwordTextInput = view.findViewById(R.id.password_text_input);
final TextInputEditText passwordEditText = view.findViewById(R.id.password_edit_text);
MaterialButton nextButton = view.findViewById(R.id.next_button);
// Set an error if the password is less than 8 characters.
nextButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (!isPasswordValid(passwordEditText.getText())) {
passwordTextInput.setError(getString(R.string.shr_error_password));
} else {
passwordTextInput.setError(null); // Clear the error
}
}
});
// Clear the error once more than 8 characters are typed.
passwordEditText.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View view, int i, KeyEvent keyEvent) {
if (isPasswordValid(passwordEditText.getText())) {
passwordTextInput.setError(null); //Clear the error
}
return false;
}
});
return view;
}
افزودن دکمه ها
در مرحله آن گاه، دو دکمه را به برگه ورود خویش اضافه میکنیم: « Cancel » و طراحی اپلیکیشن در مشهد « Next ».
ما از مولفه MDC Button به کار گیری خواهیم کرد که با یک استایل موج دار جوهری Material Design دکمه ها را اضافه می نماید .
در shr_login_fragment.xml، یک را به ، در تحت عنصرها TextInputLayout اضافه نمائید.
آنگاه دو عنصر را به اضافه فرمائید.
پوشه XML نتایج بایستی به صورت پایین باشد:
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:id="@+id/next_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:text="@string/shr_button_next" />
android:id="@+id/cancel_button"
style="@style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="12dp"
android:layout_marginRight="12dp"
android:layout_toStartOf="@id/next_button"
android:layout_toLeftOf="@id/next_button"
android:text="@string/shr_button_cancel" />
اکنون میبینید زمانی که نرمافزار را انجام میکنید، با ضربه زدن روی هر دکمه، یک موج جوهر نشان داده میشود.
رفتن به بخش آجل
در غایت، کد جاوا را به LoginFragment.java اضافه میکنیم تا دکمه “NEXT” خویش را به قطعه دیگری متصل کنیم.
متوجه خواهید شد که هرکدام از مؤلفه هایی که به طرح خویش اضافه کردیم، یک شناسه به آن تخصیص داده گردیده است.
ما از این شناسهها برای ارجاع به مؤلفههای کدمان به کار گیری می کنیم و برخی از قابلیت و امکان ها مانند تحقیق ایرادات و پیمایش را اضافه می کنیم.
بیایید یک اسلوب بولی سری isPasswordValid در LoginFragment.java در پایین () onCreateView اضافه کنیم که منطقی برای گزینش اینکه آیا سر عبور دارای اعتبار میباشد یا این که خیرمی باشد.
برای هدف ها این دمو، ما صرفا مطمئن می شویم که راز عبور دست کم 8 کاراکتر باشد:
/*
In reality, this will have more complex logic including, but not limited to, actual
authentication of the username and password.
*/
private boolean isPasswordValid(@Nullable Editable text) {
return text != null && text.length() >= 8;
}
در مرحله بعد از آن، یک کلیک listener به دکمه « NEXT» اضافه نمایید که غلط را مبتنی بر روال () isPasswordValid که ساخت و ساز کردیم تهیه و تنظیم و منزه می نماید.
در () onCreateView، این کلیک listener می بایست میان خط inflater و خط نمای بازگشتی قرار گیرد.
در مرحله سپس، بیایید یک listener کلیدی به سر عبور TextInputEditText اضافه کنیم تا به رویدادهای کلیدی که غلط را تمیز می نمایند اعتنا داشته باشیم.
این listener همینطور بایستی از () isPasswordValid برای پژوهش دارای اعتبار بودن یا این که نبودن راز عبور به کار گیری نماید.
میتوانید این گزینه را مستقیماً ذیل کلیک مستمع در () onCreateView اضافه نمائید.
سیاق onCreateView شما در حال حاضر بایستی چیزی مشابه بهاین باشد:
@Override
public View onCreateView(
@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.shr_login_fragment, container, false);
final TextInputLayout passwordTextInput = view.findViewById(R.id.password_text_input);
final TextInputEditText passwordEditText = view.findViewById(R.id.password_edit_text);
MaterialButton nextButton = view.findViewById(R.id.next_button);
// Set an error if the password is less than 8 characters.
nextButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (!isPasswordValid(passwordEditText.getText())) {
passwordTextInput.setError(getString(R.string.shr_error_password));
} else {
passwordTextInput.setError(null); // Clear the error
}
}
});
// Clear the error once more than 8 characters are typed.
passwordEditText.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View view, int i, KeyEvent keyEvent) {
if (isPasswordValid(passwordEditText.getText())) {
passwordTextInput.setError(null); //Clear the error
}
return false;
}
});
return view;
}

کارداران اثر گذار بر CPC در تبلیغات