2013-11-27 84 views
0

即時通訊工作我的第一個Android應用程序,要有耐心。在我的android模擬器中,響應式設計工作正常,但是當我創建apk並在我的設備中運行時,設計是正常的,沒有響應。任何想法? 這是我的代碼:Webview響應式設計不適用於我的設備

import android.annotation.SuppressLint; 
import android.app.Activity; 
import android.view.KeyEvent; 
import android.webkit.WebSettings; 
import android.webkit.WebSettings.PluginState; 
import android.webkit.WebView; 
import android.webkit.WebViewClient; 

public class MainActivity extends Activity { 

WebView myWebView; 

@SuppressWarnings("deprecation") 
@SuppressLint("SetJavaScriptEnabled") 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    myWebView = (WebView) findViewById(R.id.webview); 
    WebSettings webSettings = myWebView.getSettings(); 
    webSettings.setJavaScriptEnabled(true); 
    myWebView.getSettings().setPluginState(PluginState.ON); 
    myWebView.loadUrl("http://apelarse.com.ar"); 

    myWebView.setWebViewClient(new myWebViewClient()); 
} 

private class myWebViewClient extends WebViewClient { 

    @Override 
    public boolean shouldOverrideUrlLoading(WebView view, String url) { 

     view.loadUrl(url); 
     return false; 
    } 

     } 

    @Override 
public boolean onKeyDown(int keyCode, KeyEvent event) { 

     if (keyCode == KeyEvent.KEYCODE_BACK){ 
      if(myWebView.canGoBack()){ 
       myWebView.goBack(); 
       return true; 
      } 
     } 

     return super.onKeyDown(keyCode, event); 
    } 
} 

回答

0

請從這個嘗試首先你從我的代碼嘗試可能是它會幫助你我想,如果網絡響應式佈局不那麼工作它不是Android的側探頭的網絡側探頭。

public class WebViewActivity extends Activity { 
private WebView webview; 
private static final String TAG = "Main"; 
private ProgressDialog progressBar; 
private TextView header_maintext; 
private TextView headeroptiontext; 
private RelativeLayout back; 
private String url_string="http://www.google.com"; 
private String header_maintext_string="tittle"; 

/** Called when the activity is first created. */ 
@SuppressLint("SetJavaScriptEnabled") @Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    requestWindowFeature(Window.FEATURE_NO_TITLE); 
    setContentView(R.layout.webview_layout); 


    url_string = getIntent().getStringExtra("url"); 
    header_maintext_string = getIntent().getStringExtra("header_text"); 

    webview = (WebView)findViewById(R.id.webview01); 
    header_maintext= (TextView)findViewById(R.id.header_maintext); 
    header_maintext.setText(header_maintext_string); 

    headeroptiontext = (TextView)findViewById(R.id.headeroptiontext); 
    headeroptiontext.setVisibility(View.GONE); 

    WebSettings settings = webview.getSettings(); 
    settings.setJavaScriptEnabled(true); 
    webview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); 
    webview.getSettings().setLoadWithOverviewMode(true); 
    webview.getSettings().setUseWideViewPort(true); 

     back = (RelativeLayout) findViewById(R.id.back_layout); 
     back.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View arg0) 
     { 
      // TODO Auto-generated method stub 
      if(webview.canGoBack() == true) 
       { 
        webview.goBack(); 
       } 
      else 
       { 
        finish(); 
       } 
     } 
    }); 

    final AlertDialog alertDialog = new AlertDialog.Builder(this).create(); 

    progressBar = ProgressDialog.show(WebViewActivity.this, "tittle", "Loading..."); 

    webview.setWebViewClient(new WebViewClient() { 
     public boolean shouldOverrideUrlLoading(WebView view, String url) { 

      view.loadUrl(url); 
      return true; 
     } 

     public void onPageFinished(WebView view, String url) { 
      Log.i(TAG, "Finished loading URL: " +url); 
      if (progressBar.isShowing()) { 
       progressBar.dismiss(); 
      } 
     } 

     public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { 

      Toast.makeText(WebViewActivity.this, "Oh no! " + description, Toast.LENGTH_SHORT).show(); 
      alertDialog.setTitle("Error"); 
      alertDialog.setMessage(description); 
      alertDialog.setButton("OK", new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int which) { 
        return; 
       } 
      }); 
      alertDialog.show(); 
     } 
    }); 
    webview.loadUrl(url_string); 


} 
@Override 
public boolean onKeyDown(int keyCode, KeyEvent event) { 
    if(event.getAction() == KeyEvent.ACTION_DOWN){ 
     switch(keyCode) 
     { 
     case KeyEvent.KEYCODE_BACK: 
      if(webview.canGoBack() == true){ 
       webview.goBack(); 
      }else{ 
       finish(); 
      } 
      return true; 
     } 

    } 
    return super.onKeyDown(keyCode, event); 
} 
} 
+0

我測試我的網頁在鉻手機和響應式設計工作正常(www.apelarse.com.ar)。我會試着用你的代碼。 Thx很多 – user1706064

+0

雅實際上線我忘記包括在我的代碼hahahaha thnx編輯這個:)祝你好運哥們 –

+0

現在即時工作,但在幾個小時內我回到我的房子,我評論你,如果作品:)( Sory for my english,即時通訊從阿根廷) – user1706064

相關問題