Android 欢迎界面淡入效果并用WebView加载网址
2015-10-30 15:23
591 查看
1.首先是欢迎界面布局文件,只有一个背景图片:welcome.xml:
2.然后是欢迎界面java代码,WelcomeActivity.java,有淡入进入界面效果和延迟跳转效果:
3.跳转界面布局文件activity_main.xml,包括WebView控件和一个进度条:
4.跳转界面java代码MainActivity.xml,展示webview加载网页的进度条效果
云盘分享链接:http://yunpan.cn/cFzLptV942f4q 访问密码 c0da
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/ll_img" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/nav" android:orientation="vertical" > </LinearLayout>
2.然后是欢迎界面java代码,WelcomeActivity.java,有淡入进入界面效果和延迟跳转效果:
package com.example.appshell; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.view.Window; import android.view.animation.AlphaAnimation; import android.view.animation.Animation; import android.widget.LinearLayout; public class WelcomeActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // 取消标题 this.requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.welcome); startAnim();// 淡入效果跳转 // mHandler.sendEmptyMessageDelayed(GOTO_MAIN_ACTIVITY, 0);// 延迟3秒跳转 } private void startAnim() { LinearLayout welcomeImg = (LinearLayout) findViewById(R.id.ll_img); AlphaAnimation animail = new AlphaAnimation(0.1f, 1.0f); animail.setDuration(3000); welcomeImg.startAnimation(animail); animail.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationRepeat(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { Intent intent = new Intent(); intent.setClass(WelcomeActivity.this, MainActivity.class); startActivity(intent); finish(); } }); } private static final int GOTO_MAIN_ACTIVITY = 0; private Handler mHandler = new Handler() { public void handleMessage(android.os.Message msg) { switch (msg.what) { case GOTO_MAIN_ACTIVITY: Intent intent = new Intent(); intent.setClass(WelcomeActivity.this, MainActivity.class); startActivity(intent); finish(); break; default: break; } }; }; }
3.跳转界面布局文件activity_main.xml,包括WebView控件和一个进度条:
<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=".MainActivity" > <WebView android:id="@+id/webView" android:layout_width="match_parent" android:layout_height="match_parent" /> <ProgressBar android:id="@+id/pb" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" /> </RelativeLayout>
4.跳转界面java代码MainActivity.xml,展示webview加载网页的进度条效果
package com.example.appshell; import android.app.Activity; import android.os.Bundle; import android.view.KeyEvent; import android.view.View; import android.view.Window; import android.webkit.WebChromeClient; import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.ProgressBar; public class MainActivity extends Activity { private static final String URL = "http://www.cnblogs.com/_ymw/"; WebView webView; ProgressBar bar; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // 取消标题 this.requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_main); // 实例化WebView webView = (WebView) this.findViewById(R.id.webView); /** 调用loadUrl()方法进行加载内容 */ /** 设置WebView的属性,此时可以去执行JavaScript脚本 */ webView.getSettings().setJavaScriptEnabled(true); webView.setVerticalScrollbarOverlay(true); // 指定的垂直滚动条有叠加样式 WebSettings settings = webView.getSettings(); settings.setUseWideViewPort(true);// 设定支持viewport settings.setLoadWithOverviewMode(true); settings.setBuiltInZoomControls(true); settings.setSupportZoom(true);// 设定支持缩放 if (webView != null) { bar = (ProgressBar) findViewById(R.id.pb); webView.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView view, int newProgress) { if (newProgress == 100) { bar.setVisibility(View.GONE); } else { if (View.INVISIBLE == bar.getVisibility()) { bar.setVisibility(View.VISIBLE); } bar.setProgress(newProgress); } super.onProgressChanged(view, newProgress); } }); webView.loadUrl(URL); webView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { // 返回值是true的时候控制去WebView打开,为false调用系统浏览器或第三方浏览器 view.loadUrl(url); return true; } }); } } // 改写物理按键——返回的逻辑 @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { if (webView.canGoBack()) { webView.goBack();// 返回上一页面 return true; } else { System.exit(0);// 退出程序 } } return super.onKeyDown(keyCode, event); } }
云盘分享链接:http://yunpan.cn/cFzLptV942f4q 访问密码 c0da
相关文章推荐
- swift手记-trie自动机
- how can handle push notification when my app is not running
- iOS打包app发给测试人员测试
- unity shader 学习 (1)渲染管线
- iOS开发new与alloc/init的区别
- iOS 如何修改状态栏颜色为白色
- 【android】禁止Edittext弹出软键盘并且使光标正常显示,androidedittext
- Android编程单击图片实现切换效果的方法
- Android按键事件处理流程 -- 从事件被派发到View层次结构的根节点DecorView开始分析
- iOS 设置LaunchImage动画
- Android基础入门教程——8.3.12 Paint API之—— PathEffect(路径效果)
- 发布APP
- Android中visibility属性INVISIBLE与GONE的区别
- cocos sdkbox android 接入注意
- Play Framework 完整实现一个APP(十一)
- Spring测试工具返回Application
- ios使用webview浏览指定网页
- Android 屏蔽返回键、菜单键和Home键
- Mac下通过SSL获取RSA密钥与公钥
- Android读取excel文件内容