gpt4 book ai didi

android - 在 webview 准备好之前如何做进度条?

转载 作者:搜寻专家 更新时间:2023-11-01 08:44:10 26 4
gpt4 key购买 nike

我有一个带有 WebView 的应用程序,带有 HTML 代码 iframe。WebView url 通过菜单更改,需要几秒钟的时间。我想在 WebView 准备好使用之前创建 ProgressBar。我该怎么做?

注意:

如果你给我评价我检查菜单值的方式,我会很高兴

这是我在 PasteBin 中的代码: http://pastebin.com/6gXZxvds

或在这里:

主要 Activity :

public class MainActivity extends Activity {
String[] menu;
DrawerLayout dLayout;
ListView dList;
ArrayAdapter<String> adapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
menu = new String[]{"home","soccer","basketball"};
dLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
dList = (ListView) findViewById(R.id.right_drawer);
adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,menu);
dList.setAdapter(adapter);
dList.setSelector(android.R.color.holo_blue_dark);
dList.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> arg0, View v, int position, long id) {

dLayout.closeDrawers();
Bundle args = new Bundle();
args.putString("Menu", menu[position]);
Fragment detail = new DetailFragment();
detail.setArguments(args);
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction().replace(R.id.content_frame, detail).commit();

}

});

}



}

细节 fragment :

public class DetailFragment extends Fragment {
//TextView text;
String str;
@Override
public View onCreateView(LayoutInflater inflater,ViewGroup container, Bundle args) {

View view = inflater.inflate(R.layout.menu_detail_fragment, container, false);
String menu = getArguments().getString("Menu");
/*text= (TextView) view.findViewById(R.id.detail);
text.setText(menu);*/

if(menu.equals("home"))
{
str = "<iframe src='http://www.fcbj.co.il/' style='min-height: 100%; width: 100%; border: 0px;'></iframe>";
}
else if (menu.equals("soccer")) {
str = "<iframe src='http://www.fcbj.co.il/News/' style='min-height: 100%; width: 100%; border: 0px;'></iframe>";
}
else if(menu.equals("basketball"))
{
str = "<iframe src='http://www.fcbj.co.il/basketball/News/' style='min-height: 100%; width: 100%; border: 0px;'></iframe>";
}

WebView browser =(WebView)view.findViewById(R.id.webPage);
WebSettings settings = browser.getSettings();
settings.setJavaScriptEnabled(true);
browser.loadData(str,"text/html","UTF-8");


return view;
}


}

谢谢大家:)

最佳答案

尝试将 WebChromeClient 设置为 webview :

browser.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int newProgress) {
super.onProgressChanged(view, newProgress);
// change webview progress here
}
});

关于android - 在 webview 准备好之前如何做进度条?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29967189/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com