AndroidでWebビューのレンダリング優先度を設定するにはどうすればよいですか?
この例は、AndroidでWebビューのレンダリング優先度を設定する方法について示しています。
ステップ1 − Android Studioで新しいプロジェクトを作成し、[ファイル]⇒[新しいプロジェクト]に移動して、新しいプロジェクトを作成するために必要なすべての詳細を入力します。
ステップ2 −次のコードをres / layout/activity_main.xmlに追加します。
<?xml version = "1.0" encoding = "utf-8"?>
<LinearLayout xmlns:android = "https://schemas.android.com/apk/res/android"
xmlns:app = "https://schemas.android.com/apk/res-auto"
xmlns:tools = "https://schemas.android.com/tools"
android:layout_width = "match_parent"
android:gravity = "center"
android:layout_height = "match_parent"
tools:context = ".MainActivity"
android:orientation = "vertical">
<WebView
android:id = "@+id/web_view"
android:layout_width = "match_parent"
android:layout_height = "match_parent" />
</LinearLayout> 上記のコードでは、tutorialspoint.comを表示するためにWebビューを使用しています。
ステップ3 −次のコードをsrc / MainActivity.java
に追加しますpackage com.example.myapplication;
import android.app.ProgressDialog;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
@RequiresApi(api = Build.VERSION_CODES.P)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ProgressDialog progressDialog = new ProgressDialog(this);
progressDialog.setMessage("Loading Data...");
progressDialog.setCancelable(false);
WebView web_view = findViewById(R.id.web_view);
web_view.requestFocus();
web_view.getSettings().setLightTouchEnabled(true);
web_view.getSettings().setJavaScriptEnabled(true);
web_view.getSettings().setGeolocationEnabled(true);
web_view.setSoundEffectsEnabled(true);
web_view.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
web_view.getSettings().setUseWideViewPort(true);
web_view.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
web_view.loadUrl("https://www.tutorialspoint.com/");
web_view.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
if (progress < 100) {
progressDialog.show();
}
if (progress = = 100) {
progressDialog.dismiss();
}
}
});
}
} ステップ4 −次のコードをAndroidManifest.xmlに追加します
<?xml version = "1.0" encoding = "utf-8"?> <manifest xmlns:android = "https://schemas.android.com/apk/res/android" package = "com.example.myapplication"> <uses-permission android:name = "android.permission.INTERNET"/> <application android:allowBackup = "true" android:icon = "@mipmap/ic_launcher" android:label = "@string/app_name" android:roundIcon = "@mipmap/ic_launcher_round" android:supportsRtl = "true" android:theme = "@style/AppTheme"> <activity android:name = ".MainActivity"> <intent-filter> <action android:name = "android.intent.action.MAIN" /> <category android:name = "android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
アプリケーションを実行してみましょう。実際のAndroidモバイルデバイスをコンピューターに接続していると思います。 android studioからアプリを実行するには、プロジェクトのアクティビティファイルの1つを開き、ツールバーの[実行]アイコンをクリックします。オプションとしてモバイルデバイスを選択し、デフォルトの画面を表示するモバイルデバイスを確認します–
-
AndroidでVPNを設定する方法
モバイルデバイスでブラウジングしているときに、より安全な状態を維持したいですか?または、Netflixでのリージョンブロッキングを回避したいですか? VPN(仮想プライベートネットワーク)は素晴らしいオプションです。しかし、AndroidでVPNを設定できますか? AndroidデバイスにモバイルVPNをインストールして使用する方法と、選択するVPNは次のとおりです。スマートフォンでVPNを使用しない場合についても説明します。 なぜモバイルVPNを使用するのですか? 仮想プライベートネットワークは通常、デスクトップコンピューターとルーターに関連付けられています。では、なぜモバイルデバイスで
-
AndroidでローカルWebサーバーを設定する方法
Web開発者として、外出先でWebサイトやアプリケーションをデバッグおよびテストする必要があり、ワークフローに少し柔軟性を追加して生産性を向上させる必要があることがよくあります。 Androidデバイスから直接Webサーバーを実行したい場合は、Android用のKSWEBWebサーバーを必ず確認してください。 含まれるもの: lighttpdサーバーv1.4.35(SSL) nginx v1.7.3(SSL) PHP v5.6.2(SSL) MySQL v5.6.19 msmtp v1.4.32 Webインターフェイスv1.2 インストール GooglePlayス