如何使用标签来把一个进度条在应用程序中 [英] how to put a progress bar in an application using tabs

查看:193
本文介绍了如何使用标签来把一个进度条在应用程序中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有设置一系列选项卡,其中在这种情况下,每个活动被链接到网页每一个调用一个单独的活性的主要的java文件。我想implemente在标签活动的进度条,将显示被点击的链接,无论什么标签目前被选择为一个进度条。我有我可以用一个活动的进度条,但我不能让它为标签的工作。

I have a main java file that sets up a series of tabs where each one calls a seperate activity in this case each activity is linked to a webpage. I am trying to implemente a progress bar in the tab activity that will show a progress bar for when a link is clicked on regardless of what tab is currently selected. I have a progress bar that i can use for a single activity but i cant get it to work for the tabs

我有定义为

    getWindow().setFeatureInt( Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON);
   setContentView(R.layout.main );
   webview = (WebView) findViewById(R.id.webview);
   webview.setWebChromeClient(new WebChromeClient() {
       public void onProgressChanged(WebView view, int progress)   
       {
        MyActivity.setProgress(progress * 100);
           if(progress == 100)

              MyActivity.setTitle(R.string.app_name);
         }
       });

后的OnCreate()

Which goes after oncreate()

下面是主要的Java文件

Here is the main Java File

import android.app.Activity;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.widget.TabHost;
import android.widget.TextView;

public class UniversityofColorado extends TabActivity{

    WebView webview;
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

        TabHost host=getTabHost();
        Resources res = getResources();

        host.addTab(host.newTabSpec("one")
                .setIndicator("",res.getDrawable(R.drawable.ic_tab_google))
                .setContent(new Intent(this, Hello.class)));

        host.addTab(host.newTabSpec("two")
                        .setIndicator("Colorado Main Site")
                        .setContent(new Intent(this, ColoradoMainSiteBrowser.class)));

        host.addTab(host.newTabSpec("three")
                        .setIndicator("CULearn")
                        .setContent(new Intent(this, CULearnBrowser.class)));

        host.addTab(host.newTabSpec("four")
                .setIndicator("CULink")
                .setContent(new Intent(this, CULinkBrowser.class)));

        host.addTab(host.newTabSpec("five")
                .setIndicator("MyCUInfo")
                .setContent(new Intent(this, MyCUInfoBrowser.class)));

        host.addTab(host.newTabSpec("six")
                .setIndicator("", res.getDrawable(R.drawable.ic_tab_map))
                .setContent(new Intent(this, CampusBrowser.class)));

        host.addTab(host.newTabSpec("Seven")
                .setIndicator("",res.getDrawable(R.drawable.ic_tab_notes))
                .setContent(new Intent(this, NotesList.class)));

        host.addTab(host.newTabSpec("eight")
                .setIndicator("", res.getDrawable(R.drawable.ic_tab_help))
                .setContent(new Intent(this, CampusBrowser.class)));
    }   

下面是活动的一个主要的Java文件调用

Here is one of the activities that the main java file calls

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class CampusBrowser extends Activity {

    WebView webview;
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    webview = (WebView) findViewById(R.id.webview);
    webview.setWebViewClient(new HelloWebViewClient());
    webview.getSettings().setJavaScriptEnabled(true);
    webview.loadUrl("http://amath.colorado.edu/department/Maps/bldgs.html");
    }
    private class HelloWebViewClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url)
    {
    view.loadUrl(url);
    return true;
    }
    }
    public boolean onKeyDown(int keyCode, KeyEvent event) {
    if ((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack()) {
    webview.goBack();
    return true;
    }
    return super.onKeyDown(keyCode, event);
    }
    }

XML文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
/>
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    />
</LinearLayout>

如果你能帮助我想出解决办法将是pciated AP $ P $

If you could help me figure this out it would be appreciated

推荐答案

嘿,这正是我在做网页视图

Hey this is exactly what I do in my webviews

在web视图的onCreate方法[在你的情况下,它可能是你的tabActivity]做到这一点。

In the onCreate method of the webview[in your case it may be your tabActivity] do this

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setContentView(R.layout.webview_simple);
}

然后在网页视图客户做到这一点。

then in the webview client do this

private class MyWebViewClient extends WebViewClient {

public synchronized boolean shouldOverrideUrlLoading(WebView view, String url){
}// and all ur implementation

    public void onPageFinished(WebView view, String url) {
        super.onPageFinished(view, url);
        setProgressBarIndeterminateVisibility(false);
    }

    public void onPageStarted(WebView view, String url, Bitmap favicon) {
        setProgressBarIndeterminateVisibility(true);
        super.onPageStarted(view, url, favicon);            
    }

}

希望它帮助。我重写onPageFinished和​​onPageStarted在web视图客户端。它难以从onProgressChanged做到这一点。我尝试过,但我发现这是简单的。

Hope it helps. I am overriding the onPageFinished and onPageStarted in the webview client. Its difficult to do it from onProgressChanged. I tried it but I found this to be simple.

这篇关于如何使用标签来把一个进度条在应用程序中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆