Android 自定義Activity 實(shí)現(xiàn)懸浮 Dialog

轉(zhuǎn)載請(qǐng)標(biāo)明出處:http://www.reibang.com/u/a5ad093cffe8

實(shí)現(xiàn)懸浮的自定義窗體有很多方法,自定義Dialog磷斧,自定義layout 均可以實(shí)現(xiàn)。自定義activity也是可以的啸盏,今天我就介紹一下activity的實(shí)現(xiàn)方法什湘。


效果圖

如圖可以看出,當(dāng)前的窗體赎离,第一眼其實(shí)和dialog沒(méi)有什么區(qū)別逛犹,但是它是自定義activity實(shí)現(xiàn)。如何實(shí)現(xiàn)的呢梁剔?
代碼如下:
新建activity

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.dialog_show_display_mode);
        WindowManager windowManager = getWindowManager();
        Display display = windowManager.getDefaultDisplay();
        WindowManager.LayoutParams params = getWindow().getAttributes();
//        params.height = (int) (display.getHeight() * 0.3);
//        params.width = (int) (display.getWidth() * 0.8);
        params.alpha = 1.0f;
        getWindow().setAttributes(params);
        getWindow().setGravity(Gravity.CENTER);
}

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="@color/white"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="45dp">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginLeft="20dp"
            android:text="語(yǔ)音球開(kāi)啟方式"
            android:textColor="@color/bg_black"
            android:textSize="20dp" />
    </LinearLayout>

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <LinearLayout
            android:id="@+id/display_dialog_intelligence_linner"
            android:layout_width="match_parent"
            android:layout_height="65dp"
            android:orientation="horizontal">

            <ImageView
                android:id="@+id/display_dialog_intelligence_iv"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:src="@mipmap/abc_btn_radio_to_on_mtrl_000" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginLeft="10dp"
                android:text="智能顯示"
                android:textColor="@color/colorGreen2" />
        </LinearLayout>

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

        <LinearLayout
            android:id="@+id/display_dialog_custom_linner"
            android:layout_width="match_parent"
            android:layout_height="65dp"
            android:orientation="horizontal">

            <ImageView
                android:id="@+id/display_dialog_custom_iv"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:src="@mipmap/abc_btn_radio_to_on_mtrl_000" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginLeft="10dp"
                android:text="自定義顯示"
                android:textColor="@color/colorGreen2" />
        </LinearLayout>
    </LinearLayout>
</LinearLayout>

style樣式:

<style name="activityTheme" parent="@android:style/Theme.Translucent.NoTitleBar.Fullscreen">
        <item name="android:windowFrame">@null</item><!--邊框-->
        <item name="android:windowIsFloating">true</item><!--是否浮現(xiàn)在activity之上-->
        <item name="android:windowIsTranslucent">false</item><!--半透明-->
        <item name="android:windowNoTitle">true</item><!--無(wú)標(biāo)題-->
        <item name="android:background">@android:color/transparent</item>
        <item name="android:windowBackground">@android:color/transparent</item><!--背景透明-->
        <item name="android:backgroundDimEnabled">true</item><!--模糊-->
    </style>

資源文件配置activity:

<activity
            android:name=".__activity.FloatWindowDialogActivity"
            android:screenOrientation="portrait"
            android:theme="@style/activityTheme" />

ok 搞定虽画。
喜歡的可以點(diǎn)贊,微信掃一掃關(guān)注我的公眾號(hào):

微信公眾號(hào)
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末荣病,一起剝皮案震驚了整個(gè)濱河市码撰,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌个盆,老刑警劉巖脖岛,帶你破解...
    沈念sama閱讀 216,744評(píng)論 6 502
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件朵栖,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡柴梆,警方通過(guò)查閱死者的電腦和手機(jī)陨溅,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,505評(píng)論 3 392
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)轩性,“玉大人声登,你說(shuō)我怎么就攤上這事∶跎ぃ” “怎么了?”我有些...
    開(kāi)封第一講書人閱讀 163,105評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵卸察,是天一觀的道長(zhǎng)脯厨。 經(jīng)常有香客問(wèn)我,道長(zhǎng)坑质,這世上最難降的妖魔是什么合武? 我笑而不...
    開(kāi)封第一講書人閱讀 58,242評(píng)論 1 292
  • 正文 為了忘掉前任,我火速辦了婚禮涡扼,結(jié)果婚禮上稼跳,老公的妹妹穿的比我還像新娘。我一直安慰自己吃沪,他們只是感情好汤善,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,269評(píng)論 6 389
  • 文/花漫 我一把揭開(kāi)白布。 她就那樣靜靜地躺著票彪,像睡著了一般红淡。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上降铸,一...
    開(kāi)封第一講書人閱讀 51,215評(píng)論 1 299
  • 那天在旱,我揣著相機(jī)與錄音,去河邊找鬼推掸。 笑死桶蝎,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的终佛。 我是一名探鬼主播俊嗽,決...
    沈念sama閱讀 40,096評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼铃彰!你這毒婦竟也來(lái)了绍豁?” 一聲冷哼從身側(cè)響起,我...
    開(kāi)封第一講書人閱讀 38,939評(píng)論 0 274
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤牙捉,失蹤者是張志新(化名)和其女友劉穎竹揍,沒(méi)想到半個(gè)月后敬飒,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,354評(píng)論 1 311
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡芬位,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,573評(píng)論 2 333
  • 正文 我和宋清朗相戀三年无拗,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片昧碉。...
    茶點(diǎn)故事閱讀 39,745評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡英染,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出被饿,到底是詐尸還是另有隱情四康,我是刑警寧澤,帶...
    沈念sama閱讀 35,448評(píng)論 5 344
  • 正文 年R本政府宣布狭握,位于F島的核電站闪金,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏论颅。R本人自食惡果不足惜哎垦,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,048評(píng)論 3 327
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望恃疯。 院中可真熱鬧漏设,春花似錦、人聲如沸今妄。這莊子的主人今日做“春日...
    開(kāi)封第一講書人閱讀 31,683評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)蛙奖。三九已至,卻和暖如春杆兵,著一層夾襖步出監(jiān)牢的瞬間雁仲,已是汗流浹背。 一陣腳步聲響...
    開(kāi)封第一講書人閱讀 32,838評(píng)論 1 269
  • 我被黑心中介騙來(lái)泰國(guó)打工琐脏, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留攒砖,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 47,776評(píng)論 2 369
  • 正文 我出身青樓日裙,卻偏偏與公主長(zhǎng)得像吹艇,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子昂拂,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,652評(píng)論 2 354

推薦閱讀更多精彩內(nèi)容

  • Android 自定義View的各種姿勢(shì)1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 172,083評(píng)論 25 707
  • 內(nèi)容抽屜菜單ListViewWebViewSwitchButton按鈕點(diǎn)贊按鈕進(jìn)度條TabLayout圖標(biāo)下拉刷新...
    皇小弟閱讀 46,755評(píng)論 22 665
  • ¥開(kāi)啟¥ 【iAPP實(shí)現(xiàn)進(jìn)入界面執(zhí)行逐一顯】 〖2017-08-25 15:22:14〗 《//首先開(kāi)一個(gè)線程受神,因...
    小菜c閱讀 6,402評(píng)論 0 17
  • 開(kāi)門,開(kāi)燈 黃昏格侯,星辰 關(guān)門鼻听,關(guān)燈 沉重而厚實(shí)的響聲 蕩在燈光昏暗的樓道 一圈财著,又一圈┈ 見(jiàn)慣的車往人去 霓虹閃爍...
    槿年dyt閱讀 224評(píng)論 4 3
  • 學(xué)會(huì)提問(wèn)(原書第10版) 讀書筆記 前言 很多人不知道怎樣切實(shí)有效地提出一些關(guān)鍵問(wèn)題 這本書的目標(biāo)是傳授批判性的提...
    鳧水閱讀 3,637評(píng)論 0 7