• 在我们平时生活当中,经常会看到一些表白女朋友的html网页,但是Android端的表白软件可以说是基本没有,笔者在全网搜了一下,就没有一个可以用的。安卓端可以给人一种定制和精美的感觉,这是网页所做不到的,网页链接不见了就没了。因此在这里将自己写的Android软件制作流程以及代码全部开源,这里采用了web与安卓原生混合开发的技术,引入了腾讯X5内核替换WebView,可以让软件加载速度提高百分之三十。在github里,我也导入了了几款不同的背景动态模板,可以供你们进行挑选,也导入了不同的背景音乐可供选择,具体的更换方法也会在下面的博客当中详细解释的(如果不想自己敲代码的话),麻烦在Github给颗星,小弟将不胜感激!不会打包生成安装包apk的,可以直接安装的apk文件我也直接上传到github上了!零基础也可以玩儿!看了博客还能自己改!

  • Github链接:https://github.com/Geeksongs/ExpressLove
  • 安装包APK文件链接(debug版本,可直接使用):https://github.com/Geeksongs/ExpressLove/tree/master/app/debug

软件表白流程:

1.首页开屏暂停三秒,固定背景图

2.进入表白界面

3.如果想要离开,点击手机上的返回按钮,但不管怎么点也退不出去

4.开始表白

5.表白成功之后,出现烟花场景,然后跳转至微信,自动和小哥哥聊天(也可以跳转到QQ等任何软件,只需要改一个字符串就可以了)

下面是软件演示:

一.首先是我们的Mainactivity.java

这个活动(Java文件)在文件夹:ExpressLove\app\src\main\java\com\example\lenovo\expresslove下。我们在这个活动当中写进去一个hander,进入延时,延时到了之后跳转到第二个活动,这个活动让我们的首页开屏暂停三秒,固定背景图,如果想要更换背景图的你,则可以在下载下来的文件夹:ExpressLove\app\src\main\res\drawable当中的timg.png图片进行自行更换,但更换后的名称要保持一致。想要更改延时长短的你,则可以在下面的代码当中作修改,注释比较详细。

Mainactivity.java的代码如下:

  1. package com.example.lenovo.expresslove;
  2.  
  3. import android.app.Activity;
  4. import android.content.Intent;
  5. import android.os.Bundle;
  6.  
  7. import android.os.Handler;
  8. import android.support.v7.app.ActionBar;
  9. import android.support.v7.app.AppCompatActivity;
  10. import android.view.WindowManager;
  11. import android.webkit.WebViewClient;
  12.  
  13. import com.tencent.smtt.sdk.WebView;
  14.  
  15. public class MainActivity extends AppCompatActivity {
  16.  
  17. @Override
  18. protected void onCreate(Bundle savedInstanceState) {
  19. super.onCreate(savedInstanceState);
  20. setContentView(R.layout.activity_main);
  21.  
  22. ActionBar actionBar=getSupportActionBar();//后面几行都用于隐藏标题栏
  23. if(actionBar !=null)
  24. {
  25. actionBar.hide();
  26. }
  27. getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
  28. getSupportActionBar().hide();
  29. new Handler().postDelayed(new Runnable(){ // 为了减少代码使用匿名Handler创建一个延时的调用
  30. public void run() {
  31. Intent i = new Intent(MainActivity.this,Main2Activity.class);//延时之后跳转到活动2,main2activity.java
  32. MainActivity.this.startActivity(i);
  33. MainActivity.this.finish();
  34. } }, 3000);//3000表示的是延时3秒
  35. }
  36.  
  37. }

二.首页布局代码:activity_main.xml(不需要改)

在文件夹:ExpressLove\app\src\main\res\layout下的activity_main.xml 当中

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:tools="http://schemas.android.com/tools"
  4. android:layout_width="match_parent"
  5. android:layout_height="match_parent"
  6. android:orientation="vertical"
  7. android:background="@drawable/timg">
  8. </LinearLayout>

 三.进入第二个活动:(安卓程序员可以在这里进入腾讯X5内核)

main2activity.java,和Mainactivity.java在同一个文件夹下,这个活动就引入了我们的心形动态图的界面:

这部分代码由几个部分组成:

1.安卓程序员可以在加入腾讯X5内核,由于我们这个活动后面的背景动态是通过Webview来加载的,第一次打开软件的速度会偏慢,如果去掉注释删除webview控件的调用,使用X5则会提高加载速度。下面的注释也比较详细。

2.由于背后的动态是html5文件,这个文件是放置在笔者已经创建好的asset文件夹下的,如果想要更改后面的背景动态,则可以直接到ExpressLove\app\src\main\assets文件夹下查看我们已经给出的html5背景动态,如果不满意可以自己更替,笔者已经往里面注入了index.html index2.html  index3.html  index4.html 四个背景动态,效果可以自行在电脑浏览器当中查看,可以在webview代码实现处更改。如果想要本动态的背景文字,稍后我会详细解释。

3.再引入文字动画,但是动画就需要我们创建新的xml文件来完成这个动画了,这个活动里仅仅是Java代码对xml动画进行的调用,实现的是顶部标题栏文字的渐变动画,代码从animation处开始,使用的是补间动画的知识,稍后我们会给出新xml文件的代码。

4.流氓式表白过程,主要使用了对话框的技术,如果用户首先点击了软件上的button“点我啦”,则会跳转到一个对话框,而对话框又只有一个按钮,代码当中利用对话框的嵌套,从而实现点了对话框当中按钮之后又会出现新的对话框。直到点击完对话框。

5.无法返回到桌面的精美对话框dialog制作:如果用户点击了手机上的返回按钮,则会出现:“小姐姐求求你别离开我好吗?”,不管是点击确定还是返回都会返回到第二个活动当中,并不会退出软件。

  1. ackage com.example.lenovo.expresslove;
  2.  
  3. import android.app.Dialog;
  4. import android.content.DialogInterface;
  5. import android.content.Intent;
  6. import android.os.Build;
  7. import android.os.Handler;
  8. import android.support.v7.app.ActionBar;
  9. import android.support.v7.app.AlertDialog;
  10. import android.support.v7.app.AppCompatActivity;
  11. import android.os.Bundle;
  12. import android.view.KeyEvent;
  13. import android.view.View;
  14. import android.view.Window;
  15. import android.view.WindowManager;
  16. import android.view.animation.Animation;
  17. import android.view.animation.AnimationUtils;
  18. import android.webkit.WebViewClient;
  19. import android.widget.Button;
  20. import android.widget.TextView;
  21. import android.widget.Toast;
  22. import android.net.http.SslError;
  23. import android.os.Bundle;
  24. import android.support.v7.app.AppCompatActivity;
  25. import android.webkit.SslErrorHandler;
  26. import android.webkit.WebSettings;
  27. import android.webkit.WebView;
  28. import android.webkit.WebViewClient;
  29. /*import com.tencent.smtt.sdk.WebSettings;
  30. import com.tencent.smtt.sdk.WebView;*/
  31.  
  32. public class Main2Activity extends AppCompatActivity {
  33. // private WebView mWebView;
  34. private WebView webView;
  35. AlertDialog builder=null;//进入流氓式表白
  36. @Override
  37. protected void onCreate(Bundle savedInstanceState) {
  38. super.onCreate(savedInstanceState);
  39.  
  40. setContentView(R.layout.activity_main2);
    //下面被注释掉的这几行代码完全看程序员的个人意愿了,如果想要用腾讯X5内核的,就把后面的注释符号删除就可以了,同时还需要把我们的webview控件相关的
  41. /* mWebView = (com.tencent.smtt.sdk.WebView) findViewById(R.id.webView2);
  42. mWebView.loadUrl("file:///android_asset/index3.html");
  43. if (Build.VERSION.SDK_INT >= 21) {//设置顶部状态栏为半透明
  44. getWindow().setFlags(
  45. WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
  46. WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
  47. }*/
  48. final TextView textView=(TextView)findViewById(R.id.textview);
  49.  
  50. //下面是运用的webview来加载我们的h5动画,如果想使用x5的可以把下面的这些删掉,再利用上面已经注释过的代码即可。
  51.  
  52. webView = (WebView) findViewById(R.id.webView);
  53. //需要加载的网页的url
  54. webView.loadUrl("file:///android_asset/index3.html");//这里写的是assets文件夹下html文件的名称,需要带上后面的后缀名,前面的路径是安卓系统自己规定的android_asset就是表示的在assets文件夹下的意思,如果想要其他动态背景,更改index文件名即可。
  55. webView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);//自适应屏幕
  56. webView.getSettings().setLoadWithOverviewMode(true);//自适应屏幕
  57. webView.getSettings().setSupportZoom(true);
  58. webView.getSettings().setUseWideViewPort(true);//扩大比例的缩放
  59. // webView.getSettings().setBuiltInZoomControls(true);//设置是否出现缩放工具,这里我想就不出现了,影响效果
  60. WebSettings settings = webView.getSettings();
  61. // 如果访问的页面中要与Javascript交互,则webview必须设置支持Javascript
  62. settings.setJavaScriptEnabled(true);
  63. webView.setWebViewClient(new WebViewClient(){
  64. public boolean shouldOverrideUrlLoading(WebView view, String url){
  65. view.loadUrl(url);
  66. return true;
  67. }
  68. });
    //下面这里引入的是动画,在标题栏上方的文字渐变效果,从“正在加载当中”渐变到“还愣着干嘛?”
  69. Animation scaleAnimation = AnimationUtils.loadAnimation(this, R.animator.anim);
  70. textView.startAnimation(scaleAnimation);
    //这里是隐藏安卓系统本身的标题栏
  71. ActionBar actionBar=getSupportActionBar();
  72. if(actionBar!=null)
  73. {
  74. actionBar.hide();
  75. }
    //这里是设置安卓顶部状态栏为半透明状态,和我们的顶部标题栏颜色相呼应,不然的话显示时间的状态栏就是深蓝色,看起来会很烦
  76. if (Build.VERSION.SDK_INT >= ) {//设置顶部状态栏为半透明
  77. getWindow().setFlags(
  78. WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
  79. WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);}
  80.  
  81. getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
  82. getSupportActionBar().hide();
  83. new Handler().postDelayed(new Runnable(){ // 为了减少代码使用匿名Handler创建一个延时的调用
  84. public void run() {
  85. textView.setText("<----还愣着干嘛??");
  86. } }, );//文字渐变的时间为4500ms
  87.  
  88. Button button=(Button)findViewById(R.id.button);
  89. button.setOnClickListener(new View.OnClickListener() {
  90. @Override
  91. public void onClick(View view) {
  92. AlertDialog.Builder b = new AlertDialog.Builder(Main2Activity.this);
  93. //2.设置属性
  94. b.setTitle("每天做饭给你吃?");
  95.  
  96. b.setPositiveButton("好呀", new DialogInterface.OnClickListener() {
  97. @Override
  98. public void onClick(DialogInterface dialogInterface, int i) {
  99. AlertDialog.Builder c = new AlertDialog.Builder(Main2Activity.this);
  100. c.setTitle("小姐姐:");
  101. c.setMessage("每个月生活费全都给你");
  102. c.setPositiveButton("好鸭", new DialogInterface.OnClickListener() {
  103. @Override
  104. public void onClick(DialogInterface dialogInterface, int i) {
  105. AlertDialog.Builder d = new AlertDialog.Builder(Main2Activity.this);
  106. d.setTitle("小姐姐:");
  107. d.setMessage("房产证写你名字");
  108. d.setNegativeButton("好鸭", new DialogInterface.OnClickListener() {
  109. @Override
  110. public void onClick(DialogInterface dialogInterface, int i) {
  111. AlertDialog.Builder y = new AlertDialog.Builder(Main2Activity.this);
  112. y.setTitle("小姐姐");
  113. y.setMessage("每天都陪你逛街");
  114. y.setNegativeButton("好呀", new DialogInterface.OnClickListener() {
  115. @Override
  116. public void onClick(DialogInterface dialogInterface, int i) {
  117. Intent intent=new Intent(Main2Activity.this,Main3Activity.class);
  118. startActivity(intent);
  119. }
  120. });
  121. y.create();
  122. y.show();
  123. }
  124. });
  125. d.create();
  126. d.show();
  127. }
  128. });
  129. c.create();//创建
  130. c.show();//show
  131. }
  132. });
  133. b.create();//创建
  134. b.show();//show
  135.  
  136. }
  137.  
  138. });
  139. //这里是外面的括号了
  140.  
  141. }
  142.  
  143. //下面是点击返回,跳出精美对话框的按钮,不管确定还是取消都不会退出软件
  144.  
  145. public boolean onKeyUp(int keyCode, KeyEvent event) {
  146. if(keyCode == KeyEvent.KEYCODE_BACK){
  147. new CommomDialog(this, R.style.dialog, "求求你别离开我好吗?", new CommomDialog.OnCloseListener() {
  148. @Override
  149. public void onClick(Dialog dialog, boolean confirm) {
  150. if(confirm){
  151.  
  152. dialog.dismiss();
  153. }
  154.  
  155. }
  156. })
  157. .setTitle("小姐姐:").show();
  158.  
  159. }
  160. return true;
  161. }}

 四.index3.html

如果想要修改背景动态后面的文字:“Dear love”为你想要Dear的那个人,则可以在这个网页文件里面进行修改:

如果不知道怎样自己创建asset目录的同学可以参见我的前几篇博文,传送门:https://www.cnblogs.com/geeksongs/p/10673133.html 文件目录在这儿:ExpressLove\app\src\main\assets

代码如下:

  1. <!DOCTYPE html>
  2. <html lang="en" >
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>爱你</title>
  6.  
  7. <link rel="stylesheet" href="css/style.css">
  8.  
  9. </head>
  10. <body>
  11.  
  12. <link href='https://fonts.googleapis.com/css?family=Lato:100' rel='stylesheet' type='text/css'>
  13.  
  14. <canvas id="canvas" width="" height=""></canvas>
  15.  
  16. <div class="title"><b>Dear Love</b></div><!--在这里修改背景当中的文字-->
  17.  
  18. <script src='js/FastBlur.js'></script>
  19. <script src='js/jquery.min.js'></script>
  20. <script src="js/index.js"></script>
  21.  
  22. </body>
  23. </html>

从代码当中我们可以看到这里引用了不少的js文件,相关的js文件夹我已经放到了asset文件夹之下,所以就可以进行正确的调用了。如果想引入新html5动画背景的程序员,请一定要注意您html5网页所对应的javascript文件和css文件所对应的文件夹名不要和笔者这里的重复了,不然会引起一些不必要的麻烦。

五.anim.xml

这个文件是我们补间动画所用到的xml文件,首前面的scale属性被我注释掉了,这个表示的是文字或者图片的缩放,但是实际在android软件当中运行的效果不太理想,就仅仅使用了alpha的渐变属性,对文字进行渐变。创建anim.xml需要特定的方式才能够创建,而不是直接在我们的layout文件夹之下进行创建。 同学们可以自行百度/谷歌一下。

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <set xmlns:android="http://schemas.android.com/apk/res/android">
  3. <!--<scale
  4. android:duration=""
  5. android:startOffset =""
  6. android:fillBefore = "true"
  7. android:fillAfter = "false"
  8. android:fillEnabled= "true"
  9. android:repeatMode= "restart"
  10. android:repeatCount = ""
  11. android:fromXScale="0.0"
  12. android:toXScale=""
  13. android:fromYScale="0.0"
  14. android:toYScale=""
  15. android:pivotX="50%"
  16. android:pivotY="50%" />-->
  17. <alpha
  18.  
  19. android:duration=""
  20. android:startOffset =""
  21. android:fillBefore = "true"
  22. android:fillEnabled= "true"
  23. android:repeatMode= "restart"
  24. android:repeatCount = ""
  25. android:fromAlpha="0.0"
  26. android:toAlpha="1.0"
  27.  
  28. />
  29.  
  30. </set>

六.第二个活动的布局activity_main2.xml

这个布局略显复杂了一点,但是细细看看其实也不太难。主要是在整个布局的最上方我们引入了一个嵌套的相对布局,这样才可以起到替换安卓自带的标题栏的作用。如果想使用X5内核的话,直接把我已经注释掉的X5控件的主食删掉,再删除WEBVIEW的布局就好了,但是不管如何其id一定要对才行,因为我们会在第二个活动当中引入它的id!!

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:app="http://schemas.android.com/apk/res-auto"
  4. xmlns:tools="http://schemas.android.com/tools"
  5. android:layout_width="match_parent"
  6. android:layout_height="match_parent"
  7. android:orientation="vertical"
  8. tools:context=".Main2Activity">
  9. <RelativeLayout
  10. android:background="@color/mainColor"
  11. android:layout_width="match_parent"
  12. android:layout_height="17dp">
  13.  
  14. </RelativeLayout>
  15. <RelativeLayout
  16. android:background="@color/mainColor"
  17. android:layout_width="match_parent"
  18. android:layout_height="42dp">
  19. <Button
  20. android:id="@+id/button"
  21. android:layout_width="wrap_content"
  22. android:layout_height="match_parent"
  23. android:text="点我啦"/>
  24. <TextView
  25. android:id="@+id/textview"
  26. android:textSize="23dp"
  27. android:layout_alignParentRight="true"
  28. android:textColor="@color/white"
  29. android:layout_width="250dp"
  30. android:layout_height="match_parent"
  31. android:text="正在加载中,稍等....."/>
  32. </RelativeLayout>
  33. <!-- <com.tencent.smtt.sdk.WebView
  34. android:id="@+id/webView2"
  35. android:layout_width="match_parent"
  36. android:layout_height="match_parent"/>-->
  37. <WebView
  38. android:id="@+id/webView"
  39. android:layout_width="match_parent"
  40. android:layout_height="match_parent"></WebView>
  41. </LinearLayout>

最后的布局的效果如下:(真机运行出来的效果),可以看到上面的状态栏是没有蓝色的,蓝色的标题栏也被我们隐藏了,因为我们在第二个活动当中已经隐藏了这些。只是需要注意将状态栏变为半透明需要将安卓软件的API提升到21以上,没有在21以上的可以直接在gradle文件里面进行修改,修改之后在点击android studio 右上方的syic now ,再等待电脑运行一段时间就可以了。

除此之外,我们在点击返回按钮的时候会跳出一个仿微信的对话框,如下:

在第二个活动当中已经触发了这个事件,因此我们还需要在xml文件当中做一些美工,下面是我们需要编辑的第一个xml文件:

七.dialog_commom.xml

这个布局直接创建到我们的layout文件夹之下就可以了.

代码如下:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:background="@drawable/bg_round_white"
  6. android:orientation="vertical" >
  7.  
  8. <TextView
  9. android:id="@+id/title"
  10. android:layout_width="match_parent"
  11. android:layout_height="wrap_content"
  12. android:gravity="center_horizontal"
  13. android:padding="12dp"
  14. android:layout_marginTop="12dp"
  15. android:text="提示"
  16. android:textSize="20sp"
  17. android:textColor="@color/black"/>
  18.  
  19. <TextView
  20. android:id="@+id/content"
  21. android:layout_width="match_parent"
  22. android:layout_height="wrap_content"
  23. android:gravity="center"
  24. android:layout_gravity="center_horizontal"
  25. android:lineSpacingExtra="3dp"
  26. android:layout_marginLeft="40dp"
  27. android:layout_marginTop="20dp"
  28. android:layout_marginRight="40dp"
  29. android:layout_marginBottom="30dp"
  30. android:text="签到成功,获得200积分"
  31. android:textSize="16sp"
  32. android:textColor="@color/font_common_1"/>
  33. <View
  34. android:layout_width="match_parent"
  35. android:layout_height="1dp"
  36. android:background="@color/commom_background"/>
  37.  
  38. <LinearLayout
  39. android:layout_width="match_parent"
  40. android:layout_height="50dp"
  41. android:orientation="horizontal">
  42.  
  43. <TextView
  44. android:id="@+id/cancel"
  45. android:layout_width="match_parent"
  46. android:layout_height="match_parent"
  47. android:background="@drawable/bg_dialog_left_white"
  48. android:layout_weight="1.0"
  49. android:gravity="center"
  50. android:text="确定"
  51. android:textSize="12sp"
  52. android:textColor="@color/font_common_2"/>
  53.  
  54. <View
  55. android:layout_width="1dp"
  56. android:layout_height="match_parent"
  57. android:background="@color/commom_background"/>
  58.  
  59. <TextView
  60. android:id="@+id/submit"
  61. android:layout_width="match_parent"
  62. android:layout_height="match_parent"
  63. android:background="@drawable/bg_dialog_right_white"
  64. android:gravity="center"
  65. android:layout_weight="1.0"
  66. android:text="取消"
  67. android:textSize="12sp"
  68. android:textColor="@color/font_blue"/>
  69.  
  70. </LinearLayout>
  71.  
  72. </LinearLayout>

八.colors.xml

values下的文件,必须的

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <resources>
  3. <color name="colorPrimary">#3F51B5</color>
  4. <color name="colorPrimaryDark">#303F9F</color>
  5. <color name="colorAccent">#FF4081</color>
  6. <color name="mainColor">#</color>
  7.  
  8. <color name="white">#FFFFFF</color>
  9. <color name="black">#</color>
  10.  
  11. <color name="font_gray_b">#d4d4d3</color>
  12.  
  13. <color name="font_tab_1">#42369a</color>
  14. <color name="font_tab_0">#b1b1b1</color>
  15.  
  16. <color name="font_common_1">#</color>
  17. <color name="font_common_2">#a1a1a1</color>
  18. <color name="font_blue">#42369a</color>
  19.  
  20. <color name="font_green">#00cccc</color>
  21.  
  22. <color name="commom_background">#f3f3f3</color>
  23.  
  24. </resources>

九.styles.xml

  1. <resources>
  2.  
  3. <!-- Base application theme. -->
  4. <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
  5. <!-- Customize your theme here. -->
  6. <item name="colorPrimary">@color/colorPrimary</item>
  7. <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
  8. <item name="colorAccent">@color/colorAccent</item>
  9. </style>
  10.  
  11. <style name="dialog" parent="@android:style/Theme.Dialog">
  12. <item name="android:windowFrame">@null</item>
  13. <!--边框-->
  14. <item name="android:windowIsFloating">true</item>
  15. <!--是否浮现在activity之上-->
  16. <item name="android:windowIsTranslucent">false</item>
  17. <!--半透明-->
  18. <item name="android:windowNoTitle">true</item>
  19. <!--无标题-->
  20. <item name="android:windowBackground">@android:color/transparent</item>
  21. <!--背景透明-->
  22. <item name="android:backgroundDimEnabled">true</item>
  23. <!--模糊-->
  24.  
  25. </style>
  26.  
  27. <style name="AppTheme.NoActionBar">
  28. <item name="windowActionBar">false</item>
  29. <item name="windowNoTitle">true</item>
  30. </style>
  31.  
  32. <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
  33.  
  34. <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
  35.  
  36. </resources>

为了能够在点击的时候跳出这个弹框,我们还需要编写新的Java类:

九.CommomDialog.java

  1. package com.example.lenovo.expresslove;
  2.  
  3. import android.app.Dialog;
  4. import android.content.Context;
  5. import android.os.Bundle;
  6. import android.text.TextUtils;
  7. import android.view.View;
  8. import android.widget.TextView;
  9.  
  10. public class CommomDialog extends Dialog implements View.OnClickListener {
  11.  
  12. private TextView contentTxt;
  13. private TextView titleTxt;
  14. private TextView submitTxt;
  15. private TextView cancelTxt;
  16.  
  17. private Context mContext;
  18. private String content;
  19. private OnCloseListener listener;
  20. private String positiveName;
  21. private String negativeName;
  22. private String title;
  23.  
  24. public CommomDialog(Context context) {
  25. super(context);
  26. this.mContext = context;
  27. }
  28.  
  29. public CommomDialog(Context context, int themeResId, String content) {
  30. super(context, themeResId);
  31. this.mContext = context;
  32. this.content = content;
  33. }
  34.  
  35. public CommomDialog(Context context, int themeResId, String content, OnCloseListener listener) {
  36. super(context, themeResId);
  37. this.mContext = context;
  38. this.content = content;
  39. this.listener = listener;
  40. }
  41.  
  42. protected CommomDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
  43. super(context, cancelable, cancelListener);
  44. this.mContext = context;
  45. }
  46.  
  47. public CommomDialog setTitle(String title){
  48. this.title = title;
  49. return this;
  50. }
  51.  
  52. public CommomDialog setPositiveButton(String name){
  53. this.positiveName = name;
  54. return this;
  55. }
  56.  
  57. public CommomDialog setNegativeButton(String name){
  58. this.negativeName = name;
  59. return this;
  60. }
  61.  
  62. @Override
  63. protected void onCreate(Bundle savedInstanceState) {
  64. super.onCreate(savedInstanceState);
  65. setContentView(R.layout.dialog_commom);
  66. setCanceledOnTouchOutside(false);
  67. initView();
  68. }
  69.  
  70. private void initView(){
  71. contentTxt = (TextView)findViewById(R.id.content);
  72. titleTxt = (TextView)findViewById(R.id.title);
  73. submitTxt = (TextView)findViewById(R.id.submit);
  74. submitTxt.setOnClickListener(this);
  75. cancelTxt = (TextView)findViewById(R.id.cancel);
  76. cancelTxt.setOnClickListener(this);
  77.  
  78. contentTxt.setText(content);
  79. if(!TextUtils.isEmpty(positiveName)){
  80. submitTxt.setText(positiveName);
  81. }
  82.  
  83. if(!TextUtils.isEmpty(negativeName)){
  84. cancelTxt.setText(negativeName);
  85. }
  86.  
  87. if(!TextUtils.isEmpty(title)){
  88. titleTxt.setText(title);
  89. }
  90.  
  91. }
  92.  
  93. @Override
  94. public void onClick(View v) {
  95. switch (v.getId()){
  96. case R.id.cancel:
  97. if(listener != null){
  98. listener.onClick(this, false);
  99. }
  100. this.dismiss();
  101. break;
  102. case R.id.submit:
  103. if(listener != null){
  104. listener.onClick(this, true);
  105. }
  106. break;
  107. }
  108. }
  109.  
  110. public interface OnCloseListener{
  111. void onClick(Dialog dialog, boolean confirm);
  112. }
  113. }

如果想要X5内核运行好的话,还需要新建MyApplication.java类:

十.MyApplication.java

这个类如果不用X5内核,写了也没有关系,要用的话就必须写了。

  1. package com.example.lenovo.expresslove;
  2.  
  3. import android.app.Application;
  4. import android.util.Log;
  5.  
  6. import com.tencent.smtt.sdk.QbSdk;
  7.  
  8. public class MyApplication extends Application {
  9. public void onCreate() {
  10. // TODO Auto-generated method stub
  11. super.onCreate();
  12. initX5();
  13. }
  14.  
  15. /**
  16. * 初始化X5
  17. */
  18. private void initX5() {
  19. //x5內核初始化回调
  20. QbSdk.PreInitCallback cb = new QbSdk.PreInitCallback() {
  21. @Override
  22. public void onViewInitFinished(boolean arg0) {
  23. //x5內核初始化完成的回调,为true表示x5内核加载成功,否则表示x5内核加载失败,会自动切换到系统内核。
  24. Log.d("app", " onViewInitFinished is " + arg0);
  25. }
  26.  
  27. @Override
  28. public void onCoreInitFinished() {
  29. }
  30. };
  31. //x5内核初始化接口
  32. QbSdk.initX5Environment(getApplicationContext(), cb);
  33.  
  34. }
  35. }

现在前面两个主活动就编写完成了,现在来到了我们的第三个活动,烟花场景,播放完毕之后则直接跳转到微信。

十一.Main3Activity.java

  1. package com.example.lenovo.expresslove;
  2.  
  3. import android.content.ComponentName;
  4. import android.content.Context;
  5. import android.content.Intent;
  6. import android.content.pm.PackageInfo;
  7. import android.content.pm.PackageManager;
  8. import android.net.Uri;
  9. import android.os.Build;
  10. import android.os.Handler;
  11. import android.support.v7.app.ActionBar;
  12. import android.support.v7.app.AppCompatActivity;
  13. import android.os.Bundle;
  14. import android.view.WindowManager;
  15. import android.webkit.WebSettings;
  16. import android.webkit.WebView;
  17. import android.webkit.WebViewClient;
  18.  
  19. import java.util.List;
  20.  
  21. public class Main3Activity extends AppCompatActivity {
  22.  
  23. private WebView webView;
  24. @Override
  25. protected void onCreate(Bundle savedInstanceState) {
  26. super.onCreate(savedInstanceState);
  27. setContentView(R.layout.activity_main3);
  28. getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
  29. getSupportActionBar().hide();
  30. new Handler().postDelayed(new Runnable(){ // 为了减少代码使用匿名Handler创建一个延时的调用
  31. public void run() {
  32. String url="weixin://";
  33. startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
  34.  
  35. } }, );
  36. webView = (WebView) findViewById(R.id.webView2);
  37. //需要加载的网页的url
  38. webView.loadUrl("file:///android_asset/index4.html");//这里写的是assets文件夹下html文件的名称,需要带上后面的后缀名,前面的路径是安卓系统自己规定的android_asset就是表示的在assets文件夹下的意思。
  39. webView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);//自适应屏幕
  40. webView.getSettings().setLoadWithOverviewMode(true);//自适应屏幕
  41. webView.getSettings().setSupportZoom(true);
  42. webView.getSettings().setUseWideViewPort(true);//扩大比例的缩放
  43. // webView.getSettings().setBuiltInZoomControls(true);//设置是否出现缩放工具,这里我想就不出现了,影响效果
  44. WebSettings settings = webView.getSettings();
  45. // 如果访问的页面中要与Javascript交互,则webview必须设置支持Javascript
  46. settings.setJavaScriptEnabled(true);
  47. webView.setWebViewClient(new WebViewClient(){
  48. public boolean shouldOverrideUrlLoading(WebView view, String url){
  49. view.loadUrl(url);
  50. return true;
  51. }
  52. });
  53. if (Build.VERSION.SDK_INT >= ) {//设置顶部状态栏为半透明
  54. getWindow().setFlags(
  55. WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
  56. WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);}
  57.  
  58. ActionBar actionBar=getSupportActionBar();
  59. if(actionBar!=null)
  60. {
  61. actionBar.hide();
  62. }
  63. }
  64. }

下面是第三个活动布局:

十二.activity_main3.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:app="http://schemas.android.com/apk/res-auto"
  4. xmlns:tools="http://schemas.android.com/tools"
  5. android:layout_width="match_parent"
  6. android:layout_height="match_parent"
  7. tools:context=".Main3Activity">
  8. <WebView
  9. android:id="@+id/webView2"
  10. android:layout_width="match_parent"
  11. android:layout_height="match_parent">
  12.  
  13. </WebView>
  14.  
  15. </LinearLayout>

最终的动画场景如下:(这里就仅仅截屏了)

等待几秒钟之后则会自动跳转微信,等待我们也是用匿名handler来完成的。好了,差不多了,这样我们一个完整的软件就制作完成了,如果还有什么问题的话,去源码里看看嘿嘿

轻松搞定表白女朋友:Android版APP (零基础也可直接下载软件)的更多相关文章

  1. 使用BleLib的轻松搞定Android低功耗蓝牙Ble 4.0开发具体解释

    转载请注明来源: http://blog.csdn.net/kjunchen/article/details/50909410 使用BleLib的轻松搞定Android低功耗蓝牙Ble 4.0开发具体 ...

  2. 【转】轻松搞定FTP之FlashFxp全攻略

    转载网址:http://www.newhua.com/2008/0603/39163.shtml 轻松搞定FTP之FlashFxp全攻略 导读: FlashFXP是一款功能强大的FXP/FTP软件,融 ...

  3. 【微服务】之六:轻松搞定SpringCloud微服务-API网关zuul

    通过前面几篇文章的介绍,我们可以轻松搭建起来微服务体系中比较重要的几个基础构建服务.那么,在本篇博文中,我们重点讲解一下,如何将所有微服务的API同意对外暴露,这个就设计API网关的概念. 本系列教程 ...

  4. Python高级特性: 12步轻松搞定Python装饰器

    12步轻松搞定Python装饰器 通过 Python 装饰器实现DRY(不重复代码)原则:  http://python.jobbole.com/84151/   基本上一开始很难搞定python的装 ...

  5. 人脸识别JavaScript也可以轻松搞定

    前言 是不是觉得不可思议,js已经强大到这个地步? 是的,js日新月异,它在不断的进步.只要稍不留神,那我们都只能望尘莫及了. 今天我们就来看看是什么js插件可以如此厉害? 人脸识别JavaScrip ...

  6. 春节过后就是金三银四求职季,分享几个Java面试妙招,轻松搞定HR!

    春节过后就是金三银四,分享几个Java面试妙招,轻松搞定HR! 2020年了,先祝大家新年快乐! 今年IT职位依然相当热门,特别是Java开发岗位.软件开发人才在今年将有大量的就业机会.春节过后,金三 ...

  7. 盘它!基于CANN的辅助驾驶AI实战案例,轻松搞定车辆检测和车距计算!

    摘要:基于昇腾AI异构计算架构CANN(Compute Architecture for Neural Networks)的简易版辅助驾驶AI应用,具备车辆检测.车距计算等基本功能,作为辅助驾驶入门级 ...

  8. 轻松搞定javascript变量(闭包,预解析机制,变量在内存的分配 )

    变量:  存储数据的容器     1.声明        var   2.作用域       全局变量. 局部变量. 闭包(相对的全局变量):   3.类型         a.基本类型(undefi ...

  9. Webcast / 技术小视频制作方法——自己动手录制video轻松搞定

    Webcast / 技术小视频制作方法——自己动手录制video轻松搞定 http://blog.sina.com.cn/s/blog_67d387490100wdnh.html 最近申请加入MSP的 ...

随机推荐

  1. Unite Beijing 2018 参会简要分享

    一. Training Day 主讲人:鲍建运 操作:马瑞 课程包括较为完整的功能,如灯光设置,角色动画控制,Cinemachine,Timeline,AI寻路,以及最新的Post Processin ...

  2. springMVC(spring)+WebSocket案例(获取请求参数)

    开发环境(最低版本):spring 4.0+java7+tomcat7.0.47+sockjs 前端页面要引入: <script src="http://cdn.jsdelivr.ne ...

  3. USB/GPIO/SDIO

    通用串行总线(英语:Universal Serial Bus,缩写:USB)是连接计算机系统与外部设备的一种串口总线标准,也是一种输入输出接口的技术规范.它只有4根线,两个电源(5V,地线),两个数据 ...

  4. 数据库连接池dbcp和c3po的区别

    1 DBCP   DBCP是 apache 上的一个 java 连接池项目,也是 tomcat 使用的连接池组件. 2.C3P0 是一个开放源代码的JDBC连接池,它在lib目录中与Hibernate ...

  5. asp.net mvc 使用 Autocomplete 实现类似百度,谷歌动态搜索条提示框。

    Autocomplete是一个Jquery的控件,用法比较简单. 大家先看下效果: 当文本框中输入内容,自动检索数据库给出下拉框进行提示功能. 需要用此控件大家先到它的官方网站进行下载最新版本: ht ...

  6. 工作流引擎Activiti 专题

    https://github.com/Activiti/Activiti Quick Start Guide This quick start assumes: Familiarity with Ma ...

  7. thymeleaf 专题

    Thymeleaf 之 内置对象.定义变量.URL参数及标签自定义属性 如标题所述,这篇文章主要讲述Thymeleaf中的内置对象(list解析.日期格式化.数字格式化等).定义变量.获取URL的参数 ...

  8. Spring Boot 使用 Log4j2

    Java 中比较常用的日志工具类,有 Log4j.SLF4j.Commons-logging(简称jcl).Logback.Log4j2(Log4j 升级版).Jdk Logging. Spring ...

  9. Hexo博客搭建

    http://www.jianshu.com/p/e99ed60390a8 http://blog.csdn.net/xuezhisdc/article/details/53130328 注意点: 1 ...

  10. 如何最简便的利用Python实现数据可视化?当然离不开matplotlib!

    01|Figure和Subplot: matplotlib的图像全部在figure对象里面,就像是一片画布.figsize是figure的一个设置大小的属性.一个figure里面可以有无数个subpl ...