Parcourir la source

banner 修改提交

liujiangyao il y a 8 ans
Parent
commit
d10fdc807e

BIN
app/src/main/assets/home_sheep_main_img.png


+ 7 - 1
app/src/main/assets/sheep_show.html

@@ -13,6 +13,12 @@
     </style>
 </head>
 <body>
-    <img style="width:100%;" src="./main.png" alt="">
+    <img id="img" style="width:100%;" alt=""/>
+    <script>
+    function imgpath(path){
+        var img=document.getElementById("img");
+        img.src=path;
+    }
+</script>
 </body>
 </html>

+ 1 - 1
app/src/main/java/com/sheep/gamegroup/util/Jump2View.java

@@ -86,7 +86,7 @@ public class Jump2View {
      * @param context
      * @param o
      */
-    public void goLoginView(Context context, Object o){
+    public synchronized void goLoginView(Context context, Object o){
         Intent intent = new Intent(context, LoginAct.class);
         if(o != null)
             intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

+ 35 - 8
app/src/main/java/com/sheep/gamegroup/view/activity/WebviewAct.java

@@ -2,6 +2,8 @@ package com.sheep.gamegroup.view.activity;
 
 import android.os.Bundle;
 import android.view.View;
+import android.webkit.WebChromeClient;
+import android.webkit.WebSettings;
 import android.webkit.WebView;
 import android.webkit.WebViewClient;
 
@@ -33,7 +35,18 @@ public class WebviewAct extends BaseActivity {
                 .setTitleFinish(this)
                 .setTitle(this, "专属福利");
 
-        activityWebview.getSettings().setJavaScriptEnabled(true);
+        WebSettings webSettings = activityWebview.getSettings();
+
+        //允许webview对文件的操作
+        webSettings.setAllowUniversalAccessFromFileURLs(true);
+        webSettings.setAllowFileAccess(true);
+        webSettings.setAllowFileAccessFromFileURLs(true);
+        //用于js调用Android
+        webSettings.setJavaScriptEnabled(true);
+        //设置编码方式
+        webSettings.setDefaultTextEncodingName("utf-8");
+        activityWebview.setWebChromeClient(new chromClient());
+
         activityWebview.loadUrl("file:///android_asset/sheep_show.html");
 
         activityWebview.setWebViewClient(new WebViewClient() {
@@ -44,6 +57,27 @@ public class WebviewAct extends BaseActivity {
             }
         });
     }
+    private class chromClient extends WebChromeClient {
+        @Override
+        public void onProgressChanged(WebView view, int newProgress) {
+            if(newProgress==100){
+                //页面加载完成执行的操作
+                String path= "file:///android_asset/" + "home_sheep_main_img.png";
+                String action="javascript:imgpath('"+path+"')";
+                runWebView(action);
+            }
+            super.onProgressChanged(view, newProgress);
+        }
+    }
+
+    private void runWebView(final String url){
+        runOnUiThread(new Runnable() {
+            @Override
+            public void run() {
+                activityWebview.loadUrl(url);
+            }
+        });
+    }
 
     @Override
     public void initListener() {
@@ -54,11 +88,4 @@ public class WebviewAct extends BaseActivity {
     public void initData() {
 
     }
-
-    @Override
-    protected void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-        // TODO: add setContentView(...) invocation
-        ButterKnife.bind(this);
-    }
 }

+ 1 - 1
app/src/main/res/layout/splash_activity.xml

@@ -16,7 +16,7 @@
         android:layout_width="140dp"
         android:layout_height="40dp"
         android:layout_gravity="center|bottom"
-        android:layout_marginBottom="15dp"
+        android:layout_marginBottom="@dimen/content_padding_20"
         android:background="@drawable/splash_bnt_img"
         android:gravity="center"
         android:paddingBottom="@dimen/content_padding_small"

+ 2 - 1
app/src/main/res/layout/webview_act_layout.xml

@@ -9,7 +9,8 @@
     <ImageView
         android:layout_width="match_parent"
         android:layout_height="match_parent"
-        android:background="@mipmap/home_sheep_main_img"/>
+        android:background="@mipmap/home_sheep_main_img"
+        android:visibility="gone"/>
     <com.kfzs.android.view.widget.SafeWebView
         android:id="@+id/activity_webview"
         android:layout_width="match_parent"

BIN
app/src/main/res/mipmap-xhdpi/home_sheep_img.png


BIN
app/src/main/res/mipmap-xxhdpi/home_sheep_img.png