启动活动意图点击文本中的web视图 [英] Start Activity Intent on Clicking Text Inside Webview
问题描述
我在XML中的WebView这是这样如下:
I have a webview in my xml which goes like below:
<WebView
android:id="@+id/webView"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
我加载web视图是这样的:
I am loading the webview like this:
String webView_text = "Lorem ipsum..............**<a><u>Link to fire intent</u></a>**";
WebView webView= (WebView) findViewById(R.id.webView);
webView.loadData(String.format(htmlText, webView_text), "text/html", "utf-8");
webView.setWebViewClient(new WebViewClient()
{
// Override URL
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
Intent intent = new Intent(getApplicationContext(),OtherActivity.class);
startActivity(intent);
return true;
}
});
请注意,我用的HTML标签和覆盖功能火灾意图创造了我的字符串(webView_text)的链接。它是不是做在这种情况下。有什么问题吗?我不知道,如果Android的web视图支持标签(我相信它应该)。什么是提前我的错误here.Thanks。
Please notice that I am creating the link in my string (webView_text) by using the html tag and overriding the function to fire an intent. It is not doing in this case. What is the problem here? I am not sure if Android Webview supports the tag (I believe it should). What is my mistake here.Thanks in advance.
推荐答案
您可以在此通过定义清单计划在活动的意图过滤器。 样品创建活动(A)和活动(B)和定义清单是这样的:
you can this by define scheme in activity intent filter in manifest. for sample create activity (A) and activity (B) and define in manifest like this :
<activity android:name="A" >
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.VIEW" />
<data android:scheme="activity_a" />
</intent-filter>
</activity>
<activity android:name="B" >
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.VIEW" />
<data android:scheme="activity_b" />
</intent-filter>
</activity>
如果在你的HTML有临客是这样的:
if in your html have linke like this:
<a href="activity_b://b">Activity B</a>
当你点击它,启动活动B. 活动A是类似的。
when you click it , start activity B. Activity A is similar to it.
您可以从来源$ C $ C 得到源$ C $ C
you can get source code from Source Code
注意:如果使用的WebView这种方法,你必须重写方法 shouldOverrideUrlLoading()
和每个URL比较
NOTE : if using webview for this method you must override the method shouldOverrideUrlLoading()
and compare the every url.
这篇关于启动活动意图点击文本中的web视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!