gpt4 book ai didi

Android fragment WebView

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:43:21 24 4
gpt4 key购买 nike

我为我所在国家/地区的某个人开发应用

我的应用有问题

我的应用有幻灯片菜单与此应用程序 Youtube 相同。

http://i.stack.imgur.com/4hxlM.png

但是 WebView 的问题我有一个布局它有 webView

这是 webView_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:background="@drawable/background2"
android:layout_height="match_parent"
android:orientation="vertical" >

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="39dp"
android:text="@string/aboutme"
android:textAppearance="?android:attr/textAppearanceLarge" />

<WebView
android:id="@+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />

</RelativeLayout>

这是类

package com.alyousafi.SeebClub;

import com.alyousafi.SeebClub.R;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class TimeTible_forgment extends Fragment {

public TimeTible_forgment(){}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

View rootView = inflater.inflate(R.layout.webView_layout, container, false);

return rootView;
}
}

任何人都可以帮助我如何在我的 Fragment 中使用 WebView?这是个大问题请帮帮我 >>>

最佳答案

这样试试

       public class DisplayFragment extends Fragment {

private String curURL;

public void init(String url) {

curURL = url;

}

@Override
public void onActivityCreated(Bundle savedInstanceState) {

super.onActivityCreated(savedInstanceState);

}

@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container,

Bundle savedInstanceState) {

View view = inflater
.inflate(R.layout.webview_layout, container, false);

if (curURL != null) {

WebView webview = (WebView) view.findViewById(R.id.web);

webview.getSettings().setJavaScriptEnabled(true);

webview.setWebViewClient(new webClient());

webview.loadUrl(curURL);

}

return view;

}

public void updateUrl(String url) {
curURL = url;
WebView webview = (WebView) getView().findViewById(R.id.web);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl(url);
}

private class webClient extends WebViewClient {

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {

return false;

}

}

}

关于Android fragment WebView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20137646/

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