Android 获取文件名时出错
大家好,我发现从我的项目资产文件夹访问文件有困难。 这是我的xml文件Android 获取文件名时出错,android,android-fragments,android-webview,Android,Android Fragments,Android Webview,大家好,我发现从我的项目资产文件夹访问文件有困难。 这是我的xml文件 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientatio
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="androidhive.info.materialdesign.activity.HomeFragment"
android:paddingLeft="10dp"
android:paddingRight="10dp">
<!--<TextView-->
<!--android:id="@+id/label"-->
<!--android:layout_alignParentTop="true"-->
<!--android:layout_marginTop="10dp"-->
<!--android:layout_width="fill_parent"-->
<!--android:layout_height="wrap_content"-->
<!--android:gravity="center_horizontal"-->
<!--android:textSize="30sp"-->
<!--android:text="About PES"-->
<!--android:textStyle="bold"/>-->
<!--<TextView-->
<!--android:layout_below="@id/label"-->
<!--android:layout_width="fill_parent"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_marginTop="10dp"-->
<!--android:textColor="@color/text"-->
<!--android:text="@string/aboutpes"-->
<!--android:layout_centerHorizontal="true"-->
<!--android:textIsSelectable="true" />-->
<WebView android:id="@+id/webPage"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
}
如果有人告诉我哪里出了问题,我将不胜感激。这样我就可以纠正自己。试试这个
webView = (WebView) rootView.findViewById(R.id.webPage);
webView .setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
view.loadUrl(url);
return true;
}
});
webView .loadUrl("file:///android_assets/programs.html");
你遇到了什么问题?另外,请确保在AndroidManifest.xmlya中添加了INTERNET权限。我已在AndroidManifest文件中添加了INTERNET权限。。我得到的错误是网页不可用。请尝试使用
android_-asset
而不是android_-asset
非常感谢@prosper KHi-Neal,它仍然显示相同的错误-网页不可用检查您的文件夹名称,是“assets”还是“asset”。。。?
webView = (WebView) rootView.findViewById(R.id.webPage);
webView .setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
view.loadUrl(url);
return true;
}
});
webView .loadUrl("file:///android_assets/programs.html");