❶ 想從WEB開發轉到android的開發,可行么
首先,我本人也是從做web的轉行到了android。說一下心得體會:
1.做web端的轉行android比較簡單,因為有些概念是想通的,例如LinearLayout布局比較類似於div。
2.android做應用層的只需要對java做了解即可,用到的基本都是java語法。
另外,需具備多線程,網路編程等知識,這樣才會更加容易上手。
望採納,謝謝~
❷ android 跳轉webview怎麼調
代碼如下:
[java] view plain
private WebView webview;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//實例化WebView對象
webview = new WebView(this);
//設置WebView屬性,能夠執行Javascript腳本
webview.getSettings().setJavaScriptEnabled(true);
//載入需要顯示的網頁
webview.loadUrl("file:///android_asset/www/test.html");
❸ 怎樣實現android和javaweb數據交互
要想運行網頁上的js腳本,webview必須設置支持Javas cript。
Java代碼
1mWebview.getSettings().setJavas criptEnabled(true);
然後是設置webview要載入的網頁:
web的網頁:webView.loadUrl("http://www.google.com");
本地的網頁:webView.loadUrl("file:///android_asset/XX.html"); //本地的存放在:assets文件夾中
webview做完基本的初始化後我們還要要給它,加進一個回調的代理類Javas criptInterface,並給它一個調用的名稱:ncp
Java代碼
1mWebView.addJavas criptInterface(new Javas criptInterface(),"ncp");
Javas criptInterface可以是一個普通的Java類,類實現的方法,均可被js回調:
Java代碼
final class Javas criptInterface {
public int callOnJs() {
return 1000;
}
public void callOnJs2(String mode) {
//TODO
}
}
Java要調用js的方法,只需知道js的方法名稱即可:
Java代碼
1mWebView.loadUrl("javas cript:onSaveCallback()");
js 這邊就更簡單:
Js代碼
window.onload = function(){
document.getElementById('btn_1').addEventListener('click', onBtnClick, false);
var _int_value = window.ncp.callOnJs();
alert("get int from java:" + _int_value );
}
function onBtnClick() {
window.ncp.callOnJs2("click");
}
Java和js交互有以下一些特點:
1.Java 調用 js 裡面的函數,速度並不令人滿意,大概一次一兩百毫秒吧,如果要做交互性很強的事情,這種速度會讓人瘋掉的。而反過來就不一樣了, js 去調 java 的方法,速度很快,基本上 40-50 毫秒一次。所以盡量用 js 調用 java 方法,而不是 java 去調用 js 函數。
2.Java 調用 js 的函數,沒有返回值,而 Js 調用 java 方法,可以有返回值。返回值可以是基本類型、字元串,也可以是對象。如果是字元串,有個很討厭的問題,第 3 點我會講的。如果是對象,這個對象會被轉換為 js 的對象,直接可以訪問裡面的方法。但是我不推薦 java 返回給 js 的是對象,除非是必須。因為 js 收到 java 返回的對象,會產生一些交換對象,而如果這些對象的數量增加到了 500 或 600 以上,程序就會出問題。所以盡量返回基本數據類型或者字元串。
3.Js 調用 Java 的方法,返回值如果是字元串,你會發現這個字元串是 native 的,不能對它進行一些修改操作,比如想對它 substr ,取不到。怎麼解決呢?轉成 locale 的。使用 toLocaleString() 函數就可以了。不過這個函數的速度並不快,轉化的字元串如果很多,將會很耗費時間。
❹ 求助Android如何實現按鈕button跳轉到webview
給按鈕添加一個監聽,通過Intent實現跳轉就好了
❺ android下打開Web瀏覽器的幾種常見的方法
一。通過意圖實現瀏覽
由於代碼簡單,就不提供完整的源代碼,只給主要過程:
//通過下述方法打開瀏覽器
private void openBrowser(){
//urlText是一個文本輸入框,輸入網站地址
//Uri 是統一資源標識符
Uri uri = Uri.parse(urlText.getText().toString());
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
注意:輸入URL時,不要忘記「http://」部分。
二。利用視圖打開網頁
這個例子是通過調用WebKit瀏覽器引擎提供的WebView實現的。
具體源代碼如下:
/res/layout/main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<EditText
android:layout_width="240dp"
android:layout_height="wrap_content"
android:id="@+id/etWebSite"
android:hint="輸入網址"
android:singleLine="true"
android:layout_marginRight="5dp"
/>
<Button
android:id="@+id/searchBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="搜索"
android:layout_marginRight="5dp"
/>
</LinearLayout>
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<Button
android:id="@+id/backBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="上一頁"
android:layout_marginRight="5dp"
/>
<Button
android:id="@+id/nextBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="下一頁"
android:layout_marginRight="5dp"
/>
</LinearLayout>
<WebView android:id="@+id/webView1" android:layout_width="match_parent"
android:layout_height="match_parent"></WebView>
</LinearLayout>
/res/src/com.myandroid
package com.myandroid;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.webkit.URLUtil;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class WebViewActivity extends Activity {
private Button schBtn,backBtn,nextBtn;
private WebView webView;
private EditText mText;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
schBtn = (Button)findViewById(R.id.searchBtn);
mText = (EditText)findViewById(R.id.etWebSite);
webView = (WebView)findViewById(R.id.webView1);
backBtn = (Button)findViewById(R.id.backBtn);
nextBtn = (Button)findViewById(R.id.nextBtn);
schBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
//設置可以使用Javascript
webView.getSettings().setJavaScriptEnabled(true); String strURI = mText.getText().toString();
//檢測網站的合法性
if(URLUtil.isNetworkUrl(strURI)){
webView.loadUrl(strURI);
Toast.makeText(WebViewActivity.this, strURI, Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(WebViewActivity.this, "輸入非法網站\n"+strURI, Toast.LENGTH_SHORT).show();
}
}
});
backBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
if(webView.canGoBack()){
webView.goBack();
}
}
});
nextBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
if(webView.canGoForward()){
webView.goForward();
}
}
});
}
}
同時還要在AndroidManifest.xml中添加訪問網際網路的許可權:
<uses-permission android:name="android.permission.INTERNET"/>
❻ android中點擊button,跳轉到webview中打開。求大神解答
<activity
android:name="XXXX"
>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
</intent-filter>
</activity>
❼ android web端怎麼使用
須在主線程中開啟一個線程,並且使用Handler這個對象來實現數據的非同步請求.然後當請求響應完成之後才會在界面中更新數據,這應該就是android中的非同步請求機制吧..下面是整個伺服器端以及客戶端的代碼.首先我伺服器端是通過struts來完成的.所以關於struts的jar包以及Json包所依賴的jar包都要導入到web程序中去.以下是伺服器端的包圖
web.xml文件中要配置過濾器,我是把所有請求都通過struts中的action進行處理的,所以下面是web.xml中的代碼
[html] view plain print?在CODE上查看代碼片派生到我的代碼片
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>YltxServer</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<!-- 定義Struts2的核心控制器:FilterDispatcher -->
<filter>
<!-- 定義核心Filter的名稱 -->
<filter-name>struts2</filter-name>
<!-- 定義Filter的實現類 -->
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
同時按照struts中的規則,創建一個struts.xml文件,並注冊自己寫的action
[java] view plain print?在CODE上查看代碼片派生到我的代碼片
package com.maylor.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import com.opensymphony.xwork2.ActionSupport;
public class LoginAction extends ActionSupport implements ServletRequestAware,
ServletResponseAware {
/**
*
*/
private static final long serialVersionUID = 1L;
private HttpServletRequest request;
private HttpServletResponse response;
public void login() {
try {
// HttpServletRequest request =ServletActionContext.getRequest();
// HttpServletResponse response=ServletActionContext.getResponse();
this.response.setContentType("text/html;charset=utf-8");
this.response.setCharacterEncoding("UTF-8");
// 將要返回的實體對象進行json處理
// JSONObject json=JSONObject.fromObject(this.getUsername());
// 輸出格式如:{"id":1, "username":"zhangsan", "pwd":"123"}
// System.out.println(json);
// this.response.getWriter().write(json.toString());
JSONObject json = new JSONObject();
json.put("username", "username");
json.put("password", "password");
JSONObject json1 = new JSONObject();
json1.put("phone", "phone");
json1.put("tel", "tel");
JSONArray array = new JSONArray();
array.add(json);
array.add(json1);
byte[] jsonBytes = array.toString().getBytes("utf-8");
response.setContentLength(jsonBytes.length);
response.getOutputStream().write(jsonBytes);
/**
* JSONObject json=new JSONObject(); json.put("login", "login");
* byte[] jsonBytes = json.toString().getBytes("utf-8");
* response.setContentType("text/html;charset=utf-8");
* response.setContentLength(jsonBytes.length);
* response.getOutputStream().write(jsonBytes);
* response.getOutputStream().flush();
* response.getOutputStream().close();
**/
} catch (Exception e) {
e.printStackTrace();
}
// return null;
}
@Override
public void setServletResponse(HttpServletResponse arg0) {
// TODO Auto-generated method stub
this.response = arg0;
}
@Override
public void setServletRequest(HttpServletRequest arg0) {
// TODO Auto-generated method stub
this.request = arg0;
}
}
然後就是客戶端的請求了.
下面是android客戶端的代碼,記住要在AndroidMainifest.xml中加入Internet訪問許可權
<uses-permission android:name="android.permission.INTERNET">
</uses-permission>
下面就是客戶端的代碼部分了.
[java] view plain print?在CODE上查看代碼片派生到我的代碼片
package com.maylor.demo;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.Menu;
import android.widget.TextView;
public class MainActivity extends Activity {
private static String URL = "http://192.168.2.52:8080/YltxServer/login";
public Handler mHandler;
@SuppressLint("HandlerLeak")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getPDAServerData();
// Button button = (Button) findViewById(R.id.button1);
// button.setOnClickListener(new OnClickListener() {
//
// @Override
// public void onClick(View arg0) {
// // TODO Auto-generated method stub
// Intent intent = new Intent(MainActivity.this,
// PoiSearchActivity.class);
// startActivity(intent);
// }
// });
mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
if (msg.what == 1000) {
TextView view = (TextView) findViewById(R.id.textview);
String str = "";
try {
JSONArray array = new JSONArray(msg.obj.toString());
JSONObject object = array.getJSONObject(0);
str = object.getString("username");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Log.e("wangchao", str);
view.setText(str);
}
}
};
}
/**
* 請求服務
*
* @param url
*/
private void getPDAServerData() {
new Thread() {
public void run() {
HttpClient client = new DefaultHttpClient();
HttpGet request;
String msg = "";
try {
request = new HttpGet(URL);
HttpResponse response = client.execute(request);
// 判斷請求是否成功
if (response.getStatusLine().getStatusCode() == 200) {
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream in = entity.getContent();
BufferedReader buff = new BufferedReader(
new InputStreamReader(in));
String line = "";
while ((line = buff.readLine()) != null) {
msg += line;
}
Message msg1 = mHandler.obtainMessage();
msg1.what = 1000;
msg1.obj = msg;
mHandler.sendMessage(msg1);
}
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}.start();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
這個服務就算是全部完成了..整個工程
❽ 我是學Java語言為基礎的,後來在Java的基礎上學習了android開發,現在app開發不好混,想轉學web、html5
前端那些很簡單,抽出一點點時間學就可以學得很好了。重點還是其他的,你學java或者android都可以啊。
還有別聽別人說,學好前端設計一點兒都不厲害,因為html,css那些太簡單了,根本就什麼都說明不了!加油吧!
❾ android中點擊button,跳轉到webview中打開。求大神解答😭
Uri uri = Uri.parse("http://www..com");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
❿ android 手機現在現在好像賣的比較火,有點像轉andriod開發。我現在做是做web開發的,不知道好不好轉啊
基礎入門書:
Android開發範例大全
Android應用開發詳解
1)搜一下青大實訓, 大量Android學習文章,Android游戲開發視頻,Android項目
2)網路中搜「IT AIR博客」有大量Android學習文章,游戲開發視頻,Android項目:新浪微博ANDROID客戶端開發,捷通手機訂機票Android客戶端
3)「IT學習資源站 IT AIR」 ,提供Android學習討論。