我正在从Web视图中的资产文件夹加载html文件。有一个无序列表。单击每个列表项时,我想打开一个新活动。到目前为止,这是我一直在尝试的方法。但是它显示文件未找到错误。我正在附上我期望的情况的图片。请看看。它将帮助您了解我的问题。Wanted Scenario
wv_topic_details = findViewById(R.id.wv_topic_details);
wv_topic_details.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
Intent intent = new Intent(TopicDetails.this, PrachinYug.class);
startActivity(intent);
return true;
}
});
wv_topic_details.loadUrl(file_path);
webSettings = wv_topic_details.getSettings();
webSettings.setBuiltInZoomControls(true); //enable zoom facility
webSettings.setDisplayZoomControls(false); //hide the zoom control switch
AndroidManifest.xml
<activity
android:name=".TopicDetails"
android:parentActivityName=".MainActivity">
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
<action android:name="android.intent.action.VIEW"/>
<data android:scheme="prachin_yug"/>
</intent-filter>
</activity>
<activity
android:name=".PrachinYug"
android:label="@string/prachin_yug"
android:parentActivityName=".MainActivity" >
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
<action android:name="android.intent.action.VIEW"/>
<data android:scheme="prachin_yug"/>
</intent-filter>
</activity>
<activity
android:name=".MadhyaYug"
android:label="@string/madhya_yug"
android:parentActivityName=".MainActivity" >
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
<action android:name="android.intent.action.VIEW"/>
<data android:scheme="madhya_yug"/>
</intent-filter>
</activity>
<activity
android:name=".AdhunikYug"
android:label="@string/adhunik_yug"
android:parentActivityName=".MainActivity">
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
<action android:name="android.intent.action.VIEW"/>
<data android:scheme="adhunik_yug"/>
</intent-filter>
</activity>
这是html文件。该文件在TopicDetails类中。在列表中单击相应项目时,我想打开PrachinYug,Madhyaug和AdhunikYug类。目标类不是webview。它们是android listview。
<p>
আনুমানিক ....... করা যায়। যথা-
</p>
<ul>
<li><a href="prachin_yug">প্রাচীন যুগ</a></li>
<li><a href="madhya_yug">মধ্যযুগ</a></li>
<li><a href="adhunik_yug">আধুনিক যুগ</a></li>
</ul>
答案 0 :(得分:0)
主要活动:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView webview = findViewById(R.id.webview);
webview.loadUrl("file:///android_asset/yourfile.html");
webview.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url{
if (url.equals("Your URL inside yourfile.html")) {
startActivity(new Intent(this, YourActivity.class));
}
return true;
}
});
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="@+id/webview_contributors"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>