輕鬆搞定表白女友:Android版APP (零基礎也可前往Github免費下載軟件)

  • 在咱們平時生活當中,常常會看到一些表白女友的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

 

軟件表白流程:javascript

1.首頁開屏暫停三秒,固定背景圖css

2.進入表白界面html

3.若是想要離開,點擊手機上的返回按鈕,但無論怎麼點也退不出去html5

4.開始表白java

5.表白成功以後,出現煙花場景,而後跳轉至微信,自動和小哥哥聊天(也能夠跳轉到QQ等任何軟件,只須要改一個字符串就能夠了)jquery

 

下面是軟件演示:android

 

一.首先是咱們的Mainactivity.javagit

這個活動(Java文件)在文件夾:ExpressLove\app\src\main\java\com\example\lenovo\expresslove下。咱們在這個活動當中寫進去一個hander,進入延時,延時到了以後跳轉到第二個活動,這個活動讓咱們的首頁開屏暫停三秒,固定背景圖,若是想要更換背景圖的你,則能夠在下載下來的文件夾:ExpressLove\app\src\main\res\drawable當中的timg.png圖片進行自行更換,但更換後的名稱要保持一致。想要更改延時長短的你,則能夠在下面的代碼當中做修改,註釋比較詳細。程序員

Mainactivity.java的代碼以下:github

package com.example.lenovo.expresslove;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import android.os.Handler;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.view.WindowManager;
import android.webkit.WebViewClient;

import com.tencent.smtt.sdk.WebView;


public class MainActivity extends AppCompatActivity {




    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ActionBar actionBar=getSupportActionBar();//後面幾行都用於隱藏標題欄
        if(actionBar !=null)
        {
            actionBar.hide();
        }
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getSupportActionBar().hide();
new Handler().postDelayed(new Runnable(){ // 爲了減小代碼使用匿名Handler建立一個延時的調用 public void run() { Intent i = new Intent(MainActivity.this,Main2Activity.class);//延時以後跳轉到活動2,main2activity.java MainActivity.this.startActivity(i); MainActivity.this.finish(); } }, 3000);//3000表示的是延時3秒 } }

二.首頁佈局代碼:activity_main.xml(不須要改)

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

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    android:orientation="vertical"
    android:background="@drawable/timg">
</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製做:若是用戶點擊了手機上的返回按鈕,則會出現:「小姐姐求求你別離開我好嗎?」,不論是點擊肯定仍是返回都會返回到第二個活動當中,並不會退出軟件。

ackage com.example.lenovo.expresslove;

import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Build;
import android.os.Handler;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import android.net.http.SslError;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.webkit.SslErrorHandler;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
/*import com.tencent.smtt.sdk.WebSettings;
import com.tencent.smtt.sdk.WebView;*/

public class Main2Activity extends AppCompatActivity {
  //  private WebView mWebView;
  private WebView webView;
    AlertDialog builder=null;//進入流氓式表白
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main2);
//下面被註釋掉的這幾行代碼徹底看程序員的我的意願了,若是想要用騰訊X5內核的,就把後面的註釋符號刪除就能夠了,同時還須要把咱們的webview控件相關的
/* mWebView = (com.tencent.smtt.sdk.WebView) findViewById(R.id.webView2); mWebView.loadUrl("file:///android_asset/index3.html"); if (Build.VERSION.SDK_INT >= 21) {//設置頂部狀態欄爲半透明 getWindow().setFlags( WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); }*/ final TextView textView=(TextView)findViewById(R.id.textview); //下面是運用的webview來加載咱們的h5動畫,若是想使用x5的能夠把下面的這些刪掉,再利用上面已經註釋過的代碼便可。 webView = (WebView) findViewById(R.id.webView); //須要加載的網頁的url webView.loadUrl("file:///android_asset/index3.html");//這裏寫的是assets文件夾下html文件的名稱,須要帶上後面的後綴名,前面的路徑是安卓系統本身規定的android_asset就是表示的在assets文件夾下的意思,若是想要其餘動態背景,更改index文件名便可。 webView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);//自適應屏幕 webView.getSettings().setLoadWithOverviewMode(true);//自適應屏幕 webView.getSettings().setSupportZoom(true); webView.getSettings().setUseWideViewPort(true);//擴大比例的縮放 // webView.getSettings().setBuiltInZoomControls(true);//設置是否出現縮放工具,這裏我想就不出現了,影響效果 WebSettings settings = webView.getSettings(); // 若是訪問的頁面中要與Javascript交互,則webview必須設置支持Javascript settings.setJavaScriptEnabled(true); webView.setWebViewClient(new WebViewClient(){ public boolean shouldOverrideUrlLoading(WebView view, String url){ view.loadUrl(url); return true; } });
//下面這裏引入的是動畫,在標題欄上方的文字漸變效果,從「正在加載當中」漸變到「還愣着幹嗎?」 Animation scaleAnimation
= AnimationUtils.loadAnimation(this, R.animator.anim); textView.startAnimation(scaleAnimation);
//這裏是隱藏安卓系統自己的標題欄 ActionBar actionBar
=getSupportActionBar(); if(actionBar!=null) { actionBar.hide(); }
//這裏是設置安卓頂部狀態欄爲半透明狀態,和咱們的頂部標題欄顏色相呼應,否則的話顯示時間的狀態欄就是深藍色,看起來會很煩
if (Build.VERSION.SDK_INT >= 21) {//設置頂部狀態欄爲半透明 getWindow().setFlags( WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);} getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); getSupportActionBar().hide();
new Handler().postDelayed(new Runnable(){ // 爲了減小代碼使用匿名Handler建立一個延時的調用 public void run() { textView.setText("<----還愣着幹嗎??"); } }, 4500);//文字漸變的時間爲4500ms Button button=(Button)findViewById(R.id.button); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { AlertDialog.Builder b = new AlertDialog.Builder(Main2Activity.this); //2.設置屬性 b.setTitle("天天作飯給你吃?"); b.setPositiveButton("好呀", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { AlertDialog.Builder c = new AlertDialog.Builder(Main2Activity.this); c.setTitle("小姐姐:"); c.setMessage("每月生活費全都給你"); c.setPositiveButton("好鴨", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { AlertDialog.Builder d = new AlertDialog.Builder(Main2Activity.this); d.setTitle("小姐姐:"); d.setMessage("房產證寫你名字"); d.setNegativeButton("好鴨", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { AlertDialog.Builder y = new AlertDialog.Builder(Main2Activity.this); y.setTitle("小姐姐"); y.setMessage("天天都陪你逛街"); y.setNegativeButton("好呀", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { Intent intent=new Intent(Main2Activity.this,Main3Activity.class); startActivity(intent); } }); y.create(); y.show(); } }); d.create(); d.show(); } }); c.create();//建立 c.show();//show } }); b.create();//建立 b.show();//show } }); //這裏是外面的括號了 } //下面是點擊返回,跳出精美對話框的按鈕,無論肯定仍是取消都不會退出軟件 public boolean onKeyUp(int keyCode, KeyEvent event) { if(keyCode == KeyEvent.KEYCODE_BACK){ new CommomDialog(this, R.style.dialog, "求求你別離開我好嗎?", new CommomDialog.OnCloseListener() { @Override public void onClick(Dialog dialog, boolean confirm) { if(confirm){ dialog.dismiss(); } } }) .setTitle("小姐姐:").show(); } return true; }}

 四.index3.html

若是想要修改背景動態後面的文字:「Dear love」爲你想要Dear的那我的,則能夠在這個網頁文件裏面進行修改:

若是不知道怎樣本身建立asset目錄的同窗能夠參見個人前幾篇博文,傳送門:http://www.javashuo.com/article/p-hkdeboem-s.html 文件目錄在這兒:ExpressLove\app\src\main\assets

代碼以下:

<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<title>愛你</title>

<link rel="stylesheet" href="css/style.css">

</head>
<body>

<link href='https://fonts.googleapis.com/css?family=Lato:100' rel='stylesheet' type='text/css'>

<canvas id="canvas" width="800" height="500"></canvas>

<div class="title"><b>Dear Love</b></div><!--在這裏修改背景當中的文字-->

<script src='js/FastBlur.js'></script>
<script src='js/jquery.min.js'></script>
<script src="js/index.js"></script>

</body>
</html>

 從代碼當中咱們能夠看到這裏引用了很多的js文件,相關的js文件夾我已經放到了asset文件夾之下,因此就能夠進行正確的調用了。若是想引入新html5動畫背景的程序員,請必定要注意您html5網頁所對應的javascript文件和css文件所對應的文件夾名不要和筆者這裏的重複了,否則會引發一些沒必要要的麻煩。

五.anim.xml

這個文件是咱們補間動畫所用到的xml文件,首前面的scale屬性被我註釋掉了,這個表示的是文字或者圖片的縮放,可是實際在android軟件當中運行的效果不太理想,就僅僅使用了alpha的漸變屬性,對文字進行漸變。建立anim.xml須要特定的方式纔可以建立,而不是直接在咱們的layout文件夾之下進行建立。 同窗們能夠自行百度/谷歌一下。

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <!--<scale
        android:duration="1000"
        android:startOffset ="0"
        android:fillBefore = "true"
        android:fillAfter = "false"
        android:fillEnabled= "true"
        android:repeatMode= "restart"
        android:repeatCount = "0"
        android:fromXScale="0.0"
        android:toXScale="2"
        android:fromYScale="0.0"
        android:toYScale="2"
        android:pivotX="50%"
        android:pivotY="50%" />-->
    <alpha


    android:duration="2000"
    android:startOffset ="0"
    android:fillBefore = "true"
    android:fillEnabled= "true"
    android:repeatMode= "restart"
    android:repeatCount = "0"
        android:fromAlpha="0.0"
    android:toAlpha="1.0"

    />

</set>

六.第二個活動的佈局activity_main2.xml

這個佈局略顯複雜了一點,可是細細看看其實也不太難。主要是在整個佈局的最上方咱們引入了一個嵌套的相對佈局,這樣才能夠起到替換安卓自帶的標題欄的做用。若是想使用X5內核的話,直接把我已經註釋掉的X5控件的主食刪掉,再刪除WEBVIEW的佈局就行了,可是無論如何其id必定要對才行,由於咱們會在第二個活動當中引入它的id!! 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".Main2Activity">
    <RelativeLayout
        android:background="@color/mainColor"
        android:layout_width="match_parent"
        android:layout_height="17dp">


    </RelativeLayout>
<RelativeLayout
    android:background="@color/mainColor"
    android:layout_width="match_parent"
    android:layout_height="42dp">
    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:text="點我啦"/>
<TextView
    android:id="@+id/textview"
    android:textSize="23dp"
    android:layout_alignParentRight="true"
    android:textColor="@color/white"
    android:layout_width="250dp"
    android:layout_height="match_parent"
    android:text="正在加載中,稍等....."/>
</RelativeLayout>
   <!-- <com.tencent.smtt.sdk.WebView
        android:id="@+id/webView2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>-->
    <WebView
        android:id="@+id/webView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"></WebView>
</LinearLayout>

 最後的佈局的效果以下:(真機運行出來的效果),能夠看到上面的狀態欄是沒有藍色的,藍色的標題欄也被咱們隱藏了,由於咱們在第二個活動當中已經隱藏了這些。只是須要注意將狀態欄變爲半透明須要將安卓軟件的API提高到21以上,沒有在21以上的能夠直接在gradle文件裏面進行修改,修改以後在點擊android studio 右上方的syic now ,再等待電腦運行一段時間就能夠了。

除此以外,咱們在點擊返回按鈕的時候會跳出一個仿微信的對話框,以下:

在第二個活動當中已經觸發了這個事件,所以咱們還須要在xml文件當中作一些美工,下面是咱們須要編輯的第一個xml文件:


七.dialog_commom.xml

這個佈局直接建立到咱們的layout文件夾之下就能夠了.

代碼以下:

<?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:background="@drawable/bg_round_white"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:padding="12dp"
        android:layout_marginTop="12dp"
        android:text="提示"
        android:textSize="20sp"
        android:textColor="@color/black"/>

    <TextView
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:layout_gravity="center_horizontal"
        android:lineSpacingExtra="3dp"
        android:layout_marginLeft="40dp"
        android:layout_marginTop="20dp"
        android:layout_marginRight="40dp"
        android:layout_marginBottom="30dp"
        android:text="簽到成功,得到200積分"
        android:textSize="16sp"
        android:textColor="@color/font_common_1"/>
    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@color/commom_background"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/cancel"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/bg_dialog_left_white"
            android:layout_weight="1.0"
            android:gravity="center"
            android:text="肯定"
            android:textSize="12sp"
            android:textColor="@color/font_common_2"/>

        <View
            android:layout_width="1dp"
            android:layout_height="match_parent"
            android:background="@color/commom_background"/>

        <TextView
            android:id="@+id/submit"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/bg_dialog_right_white"
            android:gravity="center"
            android:layout_weight="1.0"
            android:text="取消"
            android:textSize="12sp"
            android:textColor="@color/font_blue"/>

    </LinearLayout>

</LinearLayout>

八.colors.xml

values下的文件,必須的

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#3F51B5</color>
    <color name="colorPrimaryDark">#303F9F</color>
    <color name="colorAccent">#FF4081</color>
    <color name="mainColor">#573567</color>

    <color name="white">#FFFFFF</color>
    <color name="black">#000000</color>

    <color name="font_gray_b">#d4d4d3</color>

    <color name="font_tab_1">#42369a</color>
    <color name="font_tab_0">#b1b1b1</color>


    <color name="font_common_1">#424242</color>
    <color name="font_common_2">#a1a1a1</color>
    <color name="font_blue">#42369a</color>

    <color name="font_green">#00cccc</color>

    <color name="commom_background">#f3f3f3</color>

</resources>

九.styles.xml

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>


    <style name="dialog" parent="@android:style/Theme.Dialog">
        <item name="android:windowFrame">@null</item>
        <!--邊框-->
        <item name="android:windowIsFloating">true</item>
        <!--是否浮如今activity之上-->
        <item name="android:windowIsTranslucent">false</item>
        <!--半透明-->
        <item name="android:windowNoTitle">true</item>
        <!--無標題-->
        <item name="android:windowBackground">@android:color/transparent</item>
        <!--背景透明-->
        <item name="android:backgroundDimEnabled">true</item>
        <!--模糊-->

    </style>



    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />


</resources>

爲了可以在點擊的時候跳出這個彈框,咱們還須要編寫新的Java類:


九.CommomDialog.java

package com.example.lenovo.expresslove;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

public class CommomDialog extends Dialog implements View.OnClickListener {

    private TextView contentTxt;
    private TextView titleTxt;
    private TextView submitTxt;
    private TextView cancelTxt;

    private Context mContext;
    private String content;
    private OnCloseListener listener;
    private String positiveName;
    private String negativeName;
    private String title;

    public CommomDialog(Context context) {
        super(context);
        this.mContext = context;
    }

    public CommomDialog(Context context, int themeResId, String content) {
        super(context, themeResId);
        this.mContext = context;
        this.content = content;
    }

    public CommomDialog(Context context, int themeResId, String content, OnCloseListener listener) {
        super(context, themeResId);
        this.mContext = context;
        this.content = content;
        this.listener = listener;
    }

    protected CommomDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        this.mContext = context;
    }

    public CommomDialog setTitle(String title){
        this.title = title;
        return this;
    }

    public CommomDialog setPositiveButton(String name){
        this.positiveName = name;
        return this;
    }

    public CommomDialog setNegativeButton(String name){
        this.negativeName = name;
        return this;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_commom);
        setCanceledOnTouchOutside(false);
        initView();
    }

    private void initView(){
        contentTxt = (TextView)findViewById(R.id.content);
        titleTxt = (TextView)findViewById(R.id.title);
        submitTxt = (TextView)findViewById(R.id.submit);
        submitTxt.setOnClickListener(this);
        cancelTxt = (TextView)findViewById(R.id.cancel);
        cancelTxt.setOnClickListener(this);

        contentTxt.setText(content);
        if(!TextUtils.isEmpty(positiveName)){
            submitTxt.setText(positiveName);
        }

        if(!TextUtils.isEmpty(negativeName)){
            cancelTxt.setText(negativeName);
        }

        if(!TextUtils.isEmpty(title)){
            titleTxt.setText(title);
        }

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.cancel:
                if(listener != null){
                    listener.onClick(this, false);
                }
                this.dismiss();
                break;
            case R.id.submit:
                if(listener != null){
                    listener.onClick(this, true);
                }
                break;
        }
    }

    public interface OnCloseListener{
        void onClick(Dialog dialog, boolean confirm);
    }
}

若是想要X5內核運行好的話,還須要新建MyApplication.java類:


十.MyApplication.java

這個類若是不用X5內核,寫了也沒有關係,要用的話就必須寫了。

package com.example.lenovo.expresslove;

import android.app.Application;
import android.util.Log;

import com.tencent.smtt.sdk.QbSdk;

public class MyApplication extends Application {
    public void onCreate() {
        // TODO Auto-generated method stub
        super.onCreate();
        initX5();
    }

    /**
     * 初始化X5
     */
    private void initX5() {
        //x5內核初始化回調
        QbSdk.PreInitCallback cb = new QbSdk.PreInitCallback() {
            @Override
            public void onViewInitFinished(boolean arg0) {
                //x5內核初始化完成的回調,爲true表示x5內核加載成功,不然表示x5內核加載失敗,會自動切換到系統內核。
                Log.d("app", " onViewInitFinished is " + arg0);
            }

            @Override
            public void onCoreInitFinished() {
            }
        };
        //x5內核初始化接口
        QbSdk.initX5Environment(getApplicationContext(), cb);

    }
}

如今前面兩個主活動就編寫完成了,如今來到了咱們的第三個活動,煙花場景,播放完畢以後則直接跳轉到微信。

十一.Main3Activity.java

package com.example.lenovo.expresslove;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Handler;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.WindowManager;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import java.util.List;

public class Main3Activity extends AppCompatActivity {



    private WebView webView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main3);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getSupportActionBar().hide();
        new Handler().postDelayed(new Runnable(){ // 爲了減小代碼使用匿名Handler建立一個延時的調用
            public void run() {
                String url="weixin://";
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));



            } }, 5000);
        webView = (WebView) findViewById(R.id.webView2);
        //須要加載的網頁的url
        webView.loadUrl("file:///android_asset/index4.html");//這裏寫的是assets文件夾下html文件的名稱,須要帶上後面的後綴名,前面的路徑是安卓系統本身規定的android_asset就是表示的在assets文件夾下的意思。
        webView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);//自適應屏幕
        webView.getSettings().setLoadWithOverviewMode(true);//自適應屏幕
        webView.getSettings().setSupportZoom(true);
        webView.getSettings().setUseWideViewPort(true);//擴大比例的縮放
        // webView.getSettings().setBuiltInZoomControls(true);//設置是否出現縮放工具,這裏我想就不出現了,影響效果
        WebSettings settings = webView.getSettings();
        // 若是訪問的頁面中要與Javascript交互,則webview必須設置支持Javascript
        settings.setJavaScriptEnabled(true);
        webView.setWebViewClient(new WebViewClient(){
            public boolean shouldOverrideUrlLoading(WebView view, String url){
                view.loadUrl(url);
                return true;
            }
        });
        if (Build.VERSION.SDK_INT >= 21) {//設置頂部狀態欄爲半透明
            getWindow().setFlags(
                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);}

        ActionBar actionBar=getSupportActionBar();
        if(actionBar!=null)
        {
            actionBar.hide();
        }
    }
}

下面是第三個活動佈局:


十二.activity_main3.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Main3Activity">
<WebView
    android:id="@+id/webView2"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

</WebView>

</LinearLayout>

最終的動畫場景以下:(這裏就僅僅截屏了)

 

 等待幾秒鐘以後則會自動跳轉微信,等待咱們也是用匿名handler來完成的。好了,差很少了,這樣咱們一個完整的軟件就製做完成了,若是還有什麼問題的話,去源碼裏看看嘿嘿

相關文章
相關標籤/搜索