android 网页自动跳到浏览器
2019-04-16 15:09:19 LucasXu01 阅读数 521

一:父空间设置

android:focusable="false"

无效

 

二:父空间设置

在第一个(有可能是多布局)item的xml布局最外层加

android:descendantFocusability=“blocksDescendants”

解决问题

2011-06-09 12:38:00 jianguo_liao19840726 阅读数 2592

 

2011-06-09 12:38:00 iteye_910 阅读数 16

EditText editPhoneText = (EditText) textEntryView .findViewById(R.id.phone_number); String phone_number = editPhoneText.getText() .toString(); editPhoneText.setInputType(InputType.TYPE_CLASS_NUMBER);

2016-08-15 13:39:15 u014386474 阅读数 213
一.你要打开一个网页你可以自己写一个webview,在自己的程序中就可以打开.
wv = (WebView) findViewById(R.id.webView1);
wv.getSettings().setJavaScriptEnabled(true);
wv.setScrollBarStyle(0);
WebSettings webSettings = wv.getSettings();
webSettings.setAllowFileAccess(true);
webSettings.setBuiltInZoomControls(true);
wv.loadUrl("http://www.baidu.com");
//加载数据
wv.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int newProgress) {
if (newProgress == 100) {
MainActivity.this.setTitle("加载完成");
} else {
MainActivity.this.setTitle("加载中.......");

}
}
});
//这个是当网页上的连接被点击的时候
wv.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(final WebView view,
final String url) {
loadurl(view, url);
return true;
}
});
 // goBack()表示返回webView的上一页面
public boolean onKeyDown(int keyCoder, KeyEvent event) {
if (wv.canGoBack() && keyCoder == KeyEvent.KEYCODE_BACK) {
wv.goBack();
return true;
}
return false;
}
二.不然你就调用android内置安装的浏览器来打开网页.
   1. Uri uri Uri.parse("http://google.com");  
   2. Intent it new Intent(Intent.ACTION_VIEW, uri);  
   3. startActivity(it);
2017-07-14 11:27:57 qq_36255612 阅读数 2399

 

Android QQ交流群:813273942

package xxx


import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Message;
import android.support.annotation.Nullable;
import android.view.View;
import android.webkit.JavascriptInterface;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import java.util.ArrayList;

public class SingleWebViewFragment extends BaseWebViewFragment {
    private WebView mWebView;
    private ProgressBar mProgressBar;
    private String url = "";
    private String title = "";
    private String shareSp;
    private String shareContent;
    private ArrayList<String> loadHistoryUrls = new ArrayList<String>();

    public SingleWebViewFragment() {
    }

    private Bundle inputBundle;

    @SuppressLint("ValidFragment")
    public SingleWebViewFragment(Bundle bundle) {
        this.inputBundle = bundle;
    }

    @Override
    protected boolean shouldOverrideUrl(WebView view, String url) {
        if (url.startsWith("tel:")) {
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            startActivity(intent);
        } else if (url.startsWith("http:") || url.startsWith("https:")) {
            view.loadUrl(url);
        }
        view.loadUrl(url);
        return true;
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle bundle = getArguments();
        if (bundle == null && inputBundle != null) {
            bundle = inputBundle;
        }
        url = bundle.getString(UIHelper.HF_URL_KEY);
        title = bundle.getString(UIHelper.HF_TITLE_KEY);
        TLog.log("title", title);

        //设置数据的操作
        BaseActivity activity = (BaseActivity) getCurActivity();
        activity.setTitle(title);

    }

    @Override
    protected int getLayoutRes() {
        return R.layout.webview_single_page;
    }

    @Override
    protected void initView(View view) {

        mWebView = (WebView) view.findViewById(R.id.webView);
        mProgressBar = (ProgressBar) view.findViewById(R.id.myProgressBar);
        setWebView();
    }


    @JavascriptInterface
    @SuppressLint({"SetJavaScriptEnabled", "JavascriptInterface"})
    private void setWebView() {
        initWebView(mWebView);
        mWebView.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                if (newProgress == 100) {
                    mProgressBar.setVisibility(View.GONE);
                } else {
                    if (View.GONE == mProgressBar.getVisibility()) {
                        mProgressBar.setVisibility(View.VISIBLE);
                    }
                    mProgressBar.setProgress(newProgress);
                }
                super.onProgressChanged(view, newProgress);
            }

            @Override
            public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg) {
                //h5 target为blank时生效
                WebView newWebView = new WebView(getContext());
                RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
                newWebView.setLayoutParams(params);
                WebSettings webSettings = newWebView.getSettings();
                webSettings.setJavaScriptEnabled(true);
                webSettings.setSupportZoom(false);
                webSettings.setBuiltInZoomControls(false);// 设置是否支持缩放
                webSettings.setSaveFormData(false);
                webSettings.setDefaultTextEncodingName("utf-8");
                webSettings.setLoadsImagesAutomatically(true);    //支持自动加载图片
                webSettings.setUseWideViewPort(true);    //设置webview推荐使用的窗口,使html界面自适应屏幕
                webSettings.setLoadWithOverviewMode(true);
                webSettings.setAppCacheEnabled(true);
                webSettings.setSupportMultipleWindows(true);
                view.addView(newWebView);
                WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
                transport.setWebView(newWebView);
                resultMsg.sendToTarget();
                /*
                * true ,则说明由应用的代码处理该 url,WebView 不处理。
                *  false,则说明由 WebView 处理该 url,即用 WebView 加载该 url。
                * */
      
                return true;
            }
        });
        mWebView.loadUrl(url);
        mWebView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {

                if (url.contains("in")) {
                    UIHelper.xxx(getContext());
                    return true;
                }else if (url.contains("verify")){
                    UIHelper.xxx(getContext(), 1);
                    return true;
                }else {

                }
                return false;
            }
        });

    }


    @Override
    protected void onWebViewFailure() {
        super.onWebViewFailure();
        getActivity().finish();
    }

    @Override
    protected void onWebViewSuccess() {
        super.onWebViewSuccess();
    }

    @Override
    public boolean onBackPressed() {
        if (mWebView.canGoBack() && TDevice.hasInternet()) {
            mWebView.goBack();
            return true;//以前是true
        }
        return super.onBackPressed();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }


}

 

 

 

Android,浏览器,页面,URL

博文 来自: ultrapro
没有更多推荐了,返回首页