0
我正在爲具有加載我的網站的Web視圖的應用程序工作,並且在我的web視圖中加載頁面時加載了進度條。爲了開始檢查如何做,我嘗試創建兩個按鈕:一個是停止進度條,第二個是啓動它。View.INVISIBLE不適用於我,但View.GONE工作良好
我的進度條在應用程序啓動時默認加載。 現在我創建了停止這個按鈕,並啓動按鈕,但需要停止按鈕的按鈕後,需要重新啓動該按鈕的按鈕無法工作。 我認爲,因爲Webview在所有頁面上的加載開始在Webview下面再次開始工作,並且因爲它定義了Webview的下邊距將進度條,並且我看到當進度條工作時(當我在開始時打開應用程序)WebView到進度條(屏幕中間),當我通過停止按鈕停止它時,它將結束屏幕。當我通過開始按鈕再次啓動它時,它不顯示進度條,但它直到屏幕中間。 我在谷歌搜索,但我沒有找到任何東西。 對不起我的英語不好,我只forteen歲......
這裏我的XML代碼:我的JAVA代碼
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/content_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="0dp"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="0dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="me.filtering.netsparkmobile.MainActivity"
tools:showIn="@layout/app_bar_main">
<TextView
android:text="!אבה ךורב"
android:layout_width="70dp"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:textColor="@color/colorAccent"
android:textSize="@dimen/activity_vertical_margin"
android:id="@+id/textView6" />
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignLeft="@+id/textView6"
android:layout_alignStart="@+id/textView6"
android:id="@+id/progressBar2" />
<Button xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/button_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="stop progressbar"
android:onClick="stopPB" />
<Button
android:id="@+id/button_send2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="start progressbar"
android:onClick="startPB"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
這裏部分:
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
ProgressBar PB1;
int ProgressBarStatus=1;
public void stopPB(View arg0) {
ProgressBar PB1 = (ProgressBar) findViewById(R.id.progressBar2);
PB1.setVisibility(View.GONE);
}
public void startPB(View arg0) {
ProgressBar PB1 = (ProgressBar) findViewById(R.id.progressBar2);
PB1.setVisibility(View.INVISIBLE);
}
沒有給出什麼錯誤,當您使用View.INVISIBLE?另外,你有沒有嘗試過這種方法; progressBar.setVisibility(0); --visible progressBar.setVisibility(4); --invisible progressBar.setVisibility(8); - (喜歡解僱) –
@HonorLT這不是給我錯誤。它不工作,但不會給出錯誤。你是什麼意思progressBar.setVisibility(0); ??這不是可能的命令。 – Fox