利用style創建透明窗口的應用

閑話少說,直接上代碼

首先創建一個名為TransparentActivity的Activity
代碼如下:

package toby.personal.exercise.transparent;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

/**
 * Created by toby on 16-12-25.
 */

public class TransparentActivity extends Activity {

    private static final String TAG = "TOBY_TransparentAty";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Log.d(TAG, "Transparent Activity is created.");
        super.onCreate(savedInstanceState);

        // to do something

        finish();
    }

    @Override
    protected void onDestroy() {
        Log.d(TAG, "Transparent Activity is destroyed.");
        super.onDestroy();
    }
}

之后,修改styles.xml,在其中添加一個名為TransparentTheme的style,其代碼如下:

<resources>
    <style name="TransparentTheme" parent="android:Theme">
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowIsFloating">true</item>
        <item name="android:backgroundDimEnabled">false</item>
    </style>
</resources>

最后調整AndroidManifest.xml文件,使其大概像下面代碼這樣:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="toby.personal.exercise.transparent">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/TransparentTheme">

        <activity android:name=".TransparentActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>

</manifest>

之后運行查看運行效果

什么都沒有發生,就是正常的。

可查看應用列表之中已經多了我們的Transparent應用了。

查看加入的運行log,也可以。

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 173,288評論 25 708
  • Spring Cloud為開發人員提供了快速構建分布式系統中一些常見模式的工具(例如配置管理,服務發現,斷路器,智...
    卡卡羅2017閱讀 134,923評論 18 139
  • Spring Boot 參考指南 介紹 轉載自:https://www.gitbook.com/book/qbgb...
    毛宇鵬閱讀 46,954評論 6 342
  • 遇見獻之的那一年,我是扇語樓的歌伎。我叫桃葉- 每個客人都知道,扇語樓的桃葉舞姿卓然,色藝雙絕,但只獻歌舞,不陪客...
    夜之轉生閱讀 748評論 0 1
  • 一、今日學習 1.學習《記憶魔法師》第84-114頁,做書中作業,1小時。 2.在QQ群了學習了地點樁的圖片拍攝和...
    世話實說閱讀 233評論 0 0