※タイトルも質問内容も分かりづらいかもしれませんが、ご協力お願いできますでしょうか。
指摘を頂いたので、書き方を修正しました。
■前提
・アプリの画面(MaingActivity)のレイウアトで、AndroidOS:5.0以上の場合は、Webkit.Webivewを利用し、5.0未満はCrosswalkを利用します。
・その他は全く同じレイアウト
■内容
以下のつくりを考えているのですが、Android経験者の方から見て、どうなのか指摘やアドバイスを頂けたらと思っています。
※こうした方が汎用的に使えるなど。
〇レイウアト
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:descendantFocusability="blocksDescendants" android:orientation="vertical">
</LinearLayout><!-- ヘッダー --> <include layout="@layout/actionbar_custom" android:id="@+id/toolbar"/> <!-- webkit.webview --> <WebView android:id="@+id/webView" android:layout_width="match_parent" android:layout_height="match_parent" android:visibility="gone"/> <org.xwalk.core.XWalkView android:id="@+id/xwalkWebView" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"/> <!-- フッター --> <fragment android:id="@+id/tabBarFragment" android:name="jp.co.pal_system.tabesoda.main.fragment.TabBarFragment" android:layout_width="match_parent" android:layout_height="@dimen/tabHeight" />
〇MainActivity
// 画面項目
WebView topwebview;
XWalkView topXwalk;
・表示の切り分け判断
private void initWebView(){
if (WebViewUtil.isShowCrosswalk()){
// ■AndroidOS:5.0未満の場合
topXwalk = findViewById(R.id.topXwalkWebView);
topXwalk.setVisibility(View.VISIBLE);
}else{ // ■AndroidOS:5.0以上の場合 topwebview = findViewById(R.id.topWebView); topwebview.setVisibility(View.VISIBLE); topwebview.getSettings().setUseWideViewPort(true); topwebview.getSettings().setLoadWithOverviewMode(true); topwebview.getSettings().setJavaScriptEnabled(true); topwebview.setWebViewClient(new CustomUrlHandleWebClient()); topwebview.addJavascriptInterface(new JavaScriptInterface(topwebview), "Apps"); } }
※上記のように、すべてWebViewに関する処理をOSのバージョンによって、処理を切り分ける必要があるのですが、MainActivityですべて行うつくりを考えています。
あなたの回答
tips
プレビュー