Android通過(guò)自定義Activity實(shí)現(xiàn)懸浮的Dialog詳解
前言
其實(shí)實(shí)現(xiàn)懸浮的自定義窗體有很多方法,自定義Dialog,自定義layout 均可以實(shí)現(xiàn)。自定義activity也是可以的,今天我就介紹一下activity的實(shí)現(xiàn)方法。下面來(lái)看看詳細(xì)的介紹:

效果圖
如圖可以看出,當(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 搞定。
總結(jié)
以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,如果有疑問(wèn)大家可以留言交流,謝謝大家對(duì)腳本之家的支持。
相關(guān)文章
Android CountDownTimer案例總結(jié)
這篇文章主要介紹了Android CountDownTimer案例總結(jié),本篇文章通過(guò)簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-08-08
Android App打包加固后的APK無(wú)法安裝問(wèn)題解決
Android應(yīng)用當(dāng)中,很多隱私信息都是以 字符串的形式存在的,所以需要加密,本文主要介紹了Android App打包加固后的APK無(wú)法安裝問(wèn)題解決,感興趣的可以了解一下2024-01-01
Android通過(guò)自定義Activity實(shí)現(xiàn)懸浮的Dialog詳解
這篇文章主要給大家介紹了關(guān)于Android通過(guò)自定義Activity實(shí)現(xiàn)懸浮的Dialog的相關(guān)資料,文中給出了詳細(xì)的示例代碼供大家參考學(xué)習(xí),對(duì)大家具有一定的參考學(xué)習(xí)價(jià)值,感興趣的朋友們下面來(lái)一起看看吧。2017-05-05
Flutter利用注解生成可自定義的路由的實(shí)現(xiàn)
這篇文章主要介紹了Flutter利用注解生成可自定義的路由的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-08-08
Android入門(mén)之使用SharedPreference存取信息詳解
這篇文章主要為大家詳細(xì)介紹了Android如何使用SharedPreference實(shí)現(xiàn)存取信息,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)Android有一定的幫助,需要的可以參考一下2022-12-12
Android開(kāi)發(fā)筆記之Android中數(shù)據(jù)的存儲(chǔ)方式(一)
這篇文章主要介紹了Android開(kāi)發(fā)筆記之Android中數(shù)據(jù)的存儲(chǔ)方式(一) 的相關(guān)資料,需要的朋友可以參考下2016-01-01
Android實(shí)現(xiàn)自定義帶刪除功能的EditText實(shí)例
本篇文章主要介紹了Android實(shí)現(xiàn)自定義帶刪除功能的EditText實(shí)例,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2017-06-06
Android使用Handler實(shí)現(xiàn)倒計(jì)時(shí)功能
這篇文章主要為大家詳細(xì)介紹了Android使用Handler實(shí)現(xiàn)倒計(jì)時(shí)功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-06-06
Android+Flutter實(shí)現(xiàn)文字跑馬燈特效
跑馬燈常常被運(yùn)用在很多領(lǐng)域, 例如商場(chǎng)的電子條幅、大樓的宣傳廣告位、地鐵的廣告位。今天我們來(lái)說(shuō)一下flutter 怎么通過(guò)繪制來(lái)實(shí)現(xiàn)跑馬燈效果!,希望對(duì)大家有所幫助2022-11-11

