webview android中的Textview多个链接?

时间:2014-12-10 15:43:18

标签: android webview

我是android开发的新手.. 我只有一个像这样的文本视图

 <TextView
        android:id="@+id/txt"
        android:layout_width="wrap_content"
        android:autoLink="web"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

然后我为textview设置了settext,如

<string name="content_ontheroad">Check road conditions on your route before you leave.\nEach state or territory has a different phone number and\nwebsite detailing relevant information, or ask a local.\n\n 

\u2022&#160;&#160;&#160;ACT  13 22 81\n          
 <a href="http://www.tams.act.gov.au/roads-transport">&#160;&#160;&#160;&#160;http://www.tams.act.gov.au/roads-transport</a> \n\n
\u2022&#160;&#160;&#160;N SW 13 27 01\n 
 <a href="https://www.livetraffic.com">&#160;&#160;&#160;&#160;https://www.livetraffic.com</a> \n\n
\u2022&#160;&#160;&#160;Northern Territory 1800 246 199 or\n  <a href="http://www.securent.nt.gov.au/">&#160;&#160;&#160;&#160;http://www.securent.nt.gov.au/</a>\n\n 
\u2022&#160;&#160;&#160;Queensland 13 19 40 or\n   <a href="http://www.racq.com.au/roadconditions">&#160;&#160;&#160;&#160;http://www.racq.com.au/roadconditions</a>\n\n   
\u2022&#160;&#160;&#160;South Australia 1300 361 033 or\n 
 <a href="http://www.dpti.sa.gov.au/OutbackRoads">&#160;&#160;&#160;&#160;http://www.dpti.sa.gov.au/OutbackRoads</a>\n\n 
\u2022&#160;&#160;&#160;Tasmania 1300 135 513 or\n  <a href="http://www.dier.tas.gov.au/road_closures_and_delays">&#160;&#160;&#160;&#160;http://www.dier.tas.gov.au/road_closures_and_delays</a>\n\n  
\u2022&#160;&#160;&#160;Victoria, 13 11 70 or\n  <a href="http://www.vicroads.vic.gov.au">&#160;&#160;&#160;&#160;http://www.vicroads.vic.gov.au</a>\n\n 
\u2022&#160;&#160;&#160;Western Australia 1800 013 314 or\n<a href="https://www.mainroads.wa.gov.au/UsingRoads/RoadTrafficInformation/Pages/RoadTrafficInformation.aspx">&#160;&#160;&#160;&#160;https://www.mainroads.wa.gov.au/UsingRoads/RoadTrafficInformation/Pages/RoadTrafficInformation.aspx</a> \n\n

On country roads, always keep alert for wildlife, particularly\n at dawn or dusk when animals may be active. Be cautious,\n scanning both the road ahead and the roadsides.  Be\n aware of traffic behind you, as well as oncoming traffic.\n\n 
When safe to do so, use your high beam headlights so that\n you can see further when driving at night. However, bright\n lights can dazzle animals and rather than move off the\n road, they may remain stationery and in the path of your\n vehicle.\n\n
When travelling at speed, do not swerve to avoid hitting an\n animal, as this could put you and other motorists in danger.\n Sometimes, it may be impossible to avoid a collision with\n an animal.\n\n
More information:\n\n<a href="http://www.racv.com.au/wps/wcm/connect/racv/Internet/Primary/travel/before+you+go/driving+tips">http://www.racv.com.au/wps/wcm/connect/racv/Internet/Primary/travel/before+you+go/driving+tips</a></string>

它有一个以上的链接。在默认浏览器中启用自动链接到textview以查看打开链接。 但我需要在我的应用程序中的webview中打开它

1 个答案:

答案 0 :(得分:0)

假设您要将每个href设置为新的Web视图... 首先,为文本的每个部分提供不同的文本视图。然后哪个部分有href,只需设置下划线和颜色蓝色或任何东西。另外,您可以单独添加其他属性。 现在每个textview都会给它setOnClick事件,并将它们重定向到你的webview意图。

希望这有帮助:)