由网友(向前进)分享简介:好了,我有我的应用程序做的,我工作的一些小改动它,而有一件事是我preFER我的网页链接推出的web视图,而不是股票的浏览器...我试过这么多的东西,我不断收到错误和Eclipse保持启动调试角度,我停留。// XXXX.edu按钮按钮XXXX_Button =(按钮)findViewById(R.id.XXXX_Bu...
好了,我有我的应用程序做的,我工作的一些小改动它,而有一件事是我preFER我的网页链接推出的web视图,而不是股票的浏览器...我试过这么多的东西,我不断收到错误和Eclipse保持启动调试角度,我停留。
// XXXX.edu按钮
按钮XXXX_Button =(按钮)findViewById(R.id.XXXX_Button);
XXXXXX_Button.setOnClickListener(新View.OnClickListener()
{
公共无效的onClick(视图v)
{
开放的我们的uri = Uri.parse(http://www.XXXXXX.edu/);
startActivity(新意图(Intent.ACTION_VIEW,URI));
}
});
解决方案
您需要延长的 WebViewClient 和内推出的URL。
公共类WebActivity扩展活动
{
@覆盖
公共无效的onCreate(包savedInstanceState)
{
super.onCreate(savedInstanceState);
的WebView =(web视图)findViewById(R.id.wv);
webview.setWebViewClient(新WEBC());
webview.loadUrl(的baseUrl);
}
公共类WEBC扩展WebViewClient
{
@覆盖
公共无效onReceivedError(web视图来看,INT错误code,字符串描述,字符串failingUrl)
{
super.onReceivedError(查看,错误code,说明,failingUrl);
}
@覆盖
公共布尔shouldOverrideUrlLoading(web视图查看,字符串URL)
{
... 等等。
而在你的布局XML,
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:方向=垂直>
<的WebView
机器人:ID =@ + ID / WV
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT/>
< / LinearLayout中>
Ok, so I've got my app done, and I'm working on minor tweaks for it, and one thing is I would prefer my web links to launch in webview instead of the stock browser... I've tried so many things and I keep getting errors and eclipse keeps launching the debug perspective and I'm stuck..
// XXXX.edu Button
Button XXXX_Button = (Button)findViewById( R.id.XXXX_Button );
XXXXXX_Button.setOnClickListener( new View.OnClickListener()
{
public void onClick(View v)
{
Uri uri = Uri.parse( "http://www.XXXXXX.edu/" );
startActivity( new Intent( Intent.ACTION_VIEW, uri ) );
}
});
解决方案
You need to extend WebViewClient, and launch the url within that.
public class WebActivity extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
webview = (WebView) findViewById(R.id.wv);
webview.setWebViewClient(new WebC());
webview.loadUrl(baseUrl);
}
public class WebC extends WebViewClient
{
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
{
super.onReceivedError(view, errorCode, description, failingUrl);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
... etc.
And in your layout xml,
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<WebView
android:id="@+id/wv"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
相关推荐
最新文章