我需要显示启动画面,直到在webview中加载网页。
我使用以下代码。有可能吗?
public class MainActivity extends Activity {
private WebView view;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
String url = "http://google.com";
view = (WebView)this.findViewById(R.id.webView1);
view.clearCache(true);
WebSettings s = view.getSettings();
s.setJavaScriptEnabled(true);
s.setCacheMode(WebSettings.LOAD_DEFAULT);
s.setDomStorageEnabled(true);
view.loadUrl(url);
}
和
def get(self):
teststr ='/gs/staging.trn-test2.appspot.com/TestContainer/Barcos-2017-02-12-145657.jpg'
img = images.Image(filename=teststr)
img.resize(width=80, height=100)
thumbnail = img.execute_transforms(output_encoding=images.JPEG)
self.response.headers['Content-Type'] = 'image/jpeg'
self.response.out.write(thumbnail)
答案 0 :(得分:1)
不要为启动画面制作单独的活动,在MainActivity.java中创建启动画面布局和webview布局,并将webview的可见性设置为GONE。
打开MainActivity初始化webView并设置自定义WebViewClient。覆盖自定义webViewClient中的onPageFinished(),并在此方法中使webview可见并将屏幕布局设置为Gone。
答案 1 :(得分:0)
我的解决方案就在这里
private WebView view;
private ImageView splashScreen;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
splashScreen = (ImageView) this.findViewById(R.id.spscreen);
String url = "http://google.com";
view = (WebView)this.findViewById(R.id.webView1);
view.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
// do your stuff here
splashScreen.setVisibility(View.INVISIBLE);
view.setVisibility(View.VISIBLE);
}
});
WebSettings s = view.getSettings();
s.setJavaScriptEnabled(true);
s.setCacheMode(WebSettings.LOAD_DEFAULT);
s.setDomStorageEnabled(true);
view.loadUrl(url);
}
布局
<ImageView
android:id="@+id/spscreen"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:src="@drawable/splashscreen"
android:visibility="visible"
android:scaleType="fitXY"/>
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/webView1"
android:visibility="invisible" />