您好我在用户点击登录按钮时尝试显示循环进度条,类似于下面的屏幕截图。
问题是进度条从未显示过,即使很难,我也可以通过<{p>}更改LogInActivity.showProgressBar()
中View.VISIBLE的可见性
progressBar.setVisibility(View.VISIBLE);
。
activity_log_in.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout style="@style/layout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".activity.LogInActivity">
<!-- TW Login Form -->
<include
android:id="@+id/log_in_form"
layout="@layout/log_in"/>
<!-- Loading Indicator -->
<ProgressBar
android:id="@+id/progress_bar"
style="@style/Widget.AppCompat.ProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:indeterminate="true"/>
</FrameLayout>
styles.xml
<resources>
<!-- ... -->
<style name="layout">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">match_parent</item>
<item name="android:background">@android:color/white</item>
</style>
<!-- ... -->
</resources>
LogInActivity.java
package com.trainerworkout.trainerworkout.activity;
// import ...
/**
* As a personal trainer I need to log in so that I can have access to the app.
*/
public class LogInActivity extends AppCompatActivity {
// variable declarations ...
// butterknife allows to eliminate findViewById calls by using @Bind on fields.
...
@Bind(R.id.progress_bar)
ProgressBar progressBar;
@Bind(R.id.log_in_form)
RelativeLayout logInForm;
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.d(TAG, "onCreate()");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_log_in);
context = this;
network = new Network(this);
ButterKnife.bind(this);
applyFont();
// Sets two colors for the TextView with HTML Formatting
//noinspection deprecation
not_a_member_text_view.setText(Html.fromHtml(getString(R.string.not_a_member_string)));
if (network.userIsLoggedIn()) {
logInRefresh();
} else {
showForm();
} // else
} // onCreate()
public void logInRefresh() {
showProgressBar();
network.logInRefresh(this);
showForm();
} // logInRefresh()
// ...
public void logInButtonClick(View view) {
Log.d(TAG, "logInButtonClick()");
// Prevent multiple clicks during the network call
logInButton.setEnabled(false);
if (network.userIsLoggedIn()) {
logInRefresh();
} else {
logIn();
} // else
logInButton.setEnabled(true);
} // logInButtonClick()
/**
* Prepares the log in request to the API
*/
private void logIn() {
String email = emailEditText.getText().toString();
String password = passwordEditText.getText().toString();
if (Valid.validFields(this, email, password, emailEditText, passwordEditText)) {
showProgressBar();
network.logIn(this, email, password);
showForm();
} else {
shakeLogInButton();
} // else
} // logIn()
// ...
public void showForm() {
progressBar.setVisibility(View.GONE);
logInForm.setVisibility(View.VISIBLE);
} // showProgressBar()
public void showProgressBar() {
progressBar.setVisibility(View.VISIBLE);
logInForm.setVisibility(View.GONE);
} // showProgressBar()
} // LogInActivity
编辑 - log_in.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- TW Log In Form -->
<RelativeLayout
style="@style/layout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".activity.LogInActivity">
<LinearLayout
style="@style/layout"
android:layout_margin="@dimen/layout_margin_profile"
android:gravity="center"
android:orientation="vertical">
<!-- ... -->
<!-- Email Field -->
<EditText
android:id="@+id/email_edit_text"
style="@style/edit_text"
android:layout_height="wrap_content"
android:hint="@string/email"
android:inputType="textEmailAddress"/>
<-- ... -->
</RelativeLayout>