0
Androidでウェブビューを使用しているときに問題が発生しました。私はWeb Viewを使って簡単なアプリを作ろうとしています。このアプリはWeb ViewでWebサイトを読み込むだけです。携帯電話などの携帯端末では完璧に動作しますが、WebViewのタブレット(Nexus 10など)からアプリを開こうとすると、タブレットのバージョンではなくモバイル版のウェブサイトが読み込まれます。私は検索し、この問題の答えを見つけられませんでした。私もウェブサイトからメタタグをチェックしましたが、それはそこにあるように見えますが、それは問題ではありません。Android Webview - タブレットでもモバイル版を読み込みます。
これは私の.javaファイルです:
import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends Activity {
private static WebView view;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getActionBar().setIcon(R.drawable.icon);
String url = "http://hoinarim.ro/";
view = (WebView) this.findViewById(R.id.webView);
view.setFocusable(true);
view.setFocusableInTouchMode(true);
view.getSettings().setJavaScriptEnabled(true);
//improve webview
view.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
view.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
view.getSettings().setAppCacheEnabled(true);
view.getSettings().setDomStorageEnabled(true);
view.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
view.getSettings().setUseWideViewPort(false);
view.getSettings().setLoadWithOverviewMode(true);
view.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
view.getSettings().setSavePassword(true);
view.getSettings().setSaveFormData(true);
view.getSettings().setEnableSmoothTransition(true);
view.getSettings().setDatabaseEnabled(true);
view.getSettings().setUseWideViewPort(true);
view.setWebViewClient(new WebViewClient());
view.loadUrl(url);
view.setHorizontalScrollBarEnabled(false);
view.setOnTouchListener(new View.OnTouchListener() {
public float m_downX;
public boolean onTouch(View v, MotionEvent event) {
if (event.getPointerCount() > 1) {
//Multi touch detected
return true;
}
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
{
// save the x
m_downX = event.getX();
}
break;
case MotionEvent.ACTION_MOVE:
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP: {
// set x so that it doesn't move
event.setLocation(m_downX, event.getY());
}
break;
}
return false;
}
});
}
@Override
public void onBackPressed() {
if (view.canGoBack()) {
view.goBack();
}
else
{
super.onBackPressed();
}
}
}
そして、これは私の.xmlファイルです:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="hoinarimapp.hoinarim.MainActivity">
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/webView"/>
</RelativeLayout>
この作品を作るためにどのように任意のアイデア?それは本当にイライラしています。
はあなたにヨハンをありがとうございます。これは実際には非常にうまく動作します。私は別のユーザーエージェントの文字列を試して、動作しませんでしたが、これは魅力のように動作します。 –