我设计了这个登录表单来模拟 movil 的 facebook 登录页面。我使用 Web 服务来执行从应用程序到 API 的请求:
登录表单设计 https://i.stack.imgur.com/coEsh.png
我想要做的是在执行请求时放置一个圆形进度条,我想禁用所有组件,并将圆形进度条放在表单上,一旦请求得到处理,再次启用所有组件。这是我的 xml 代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
android:background="#dfe1ee"
android:focusable="true"
android:focusableInTouchMode="true"
tools:context="com.example.abrahamarreola.facebooklogin.LoginScreen">
<LinearLayout
android:background="#3b5998"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:src="@drawable/facebook_logo"
android:layout_width="match_parent"
android:layout_height="50dp" />
</LinearLayout>
<LinearLayout
android:background="#E3CE3B"
android:paddingBottom="2dp"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:textColor="#8f8b59"
android:textStyle="bold"
android:background="#fffacd"
android:textAlignment="center"
android:textSize="16dp"
android:text="Log in to use your Facebook account"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:paddingRight="20dp"
android:paddingLeft="20dp"
android:paddingBottom="20dp"
android:paddingTop="30dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:background="@drawable/back1"
android:orientation="horizontal"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:paddingRight="12dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="45dp"
android:layout_height="40dp"
android:src="@drawable/celphone_icon" />
<TextView
android:textStyle="bold"
android:textSize="14dp"
android:elegantTextHeight="true"
android:textColor="#3b5998"
android:layout_gravity="center_vertical"
android:gravity="center"
android:text="Use Facebook in your device everywhere."
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:padding="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:paddingTop="8dp"
android:orientation="vertical"
android:background="@drawable/back2"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputLayout
android:id="@+id/email_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="@+id/email_input"
android:singleLine="true"
android:paddingLeft="20dp"
android:hint="Email:"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/password_layout"
app:passwordToggleEnabled="true"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="@+id/password_input"
android:inputType="textPassword"
android:singleLine="true"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:hint="Password:"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.TextInputLayout>
<LinearLayout
android:padding="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/login_button"
android:textSize="16dp"
android:textColor="#ffff"
android:textStyle="bold"
android:text="Log In"
android:background="@drawable/button_login"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:paddingTop="20dp"
android:paddingLeft="70dp"
android:paddingRight="70dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/new_account_button"
android:layout_gravity="center"
android:textSize="16dp"
android:textColor="#ffff"
android:textStyle="bold"
android:text="Create new account"
android:background="@drawable/button_create_account"
android:layout_width="200dp"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/help_label"
android:textColor="#808cba"
android:layout_gravity="center"
android:paddingTop="10dp"
android:text="Forgotten Password? - Help Centre"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:background="#ffff"
android:layout_gravity="bottom"
android:layout_width="match_parent"
android:layout_height="40dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Facebook ©2019"
android:textAlignment="center"
android:textSize="16dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
您可以利用ProgressDialog
出于简单目的而不是 ProgressBar。单击您的register button
use ProgressDialog
像这样:
ProgressDialog dialog = new ProgressDialog(YourActivity.this);
dialog.setMessage("Registering...");
dialog.setCancelable(false);
dialog.setCanceledOnTouchOutside(false);
dialog.show();
要在收到成功或失败响应时关闭对话框:
dialog.dismiss();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)