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 app判斷是否有系統(tǒng)簽名步驟詳解
這篇文章主要為大家介紹了android app判斷是否有系統(tǒng)簽名步驟詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-11-11
一文詳解?Compose?Navigation?的實(shí)現(xiàn)原理
這篇文章主要介紹了一文詳解?Compose?Navigation的實(shí)現(xiàn)原理,文章通告圍繞主題展開(kāi)詳細(xì)的相關(guān)內(nèi)容介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下2022-08-08
Android中在GridView網(wǎng)格視圖上實(shí)現(xiàn)item拖拽交換的方法
這篇文章主要介紹了Android中在GridView上實(shí)現(xiàn)item拖拽交換效果的方法,比起ListView的列表?xiàng)l目交換稍顯復(fù)雜,文中先介紹了關(guān)于創(chuàng)建GridView的一些基礎(chǔ)知識(shí),需要的朋友可以參考下2016-04-04
Assert.assertEquals()方法參數(shù)詳解
本文詳細(xì)講解了Assert.assertEquals()方法參數(shù),文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-12-12
android仿音悅臺(tái)頁(yè)面交互效果實(shí)例代碼
這篇文章主要介紹了android 仿音悅臺(tái)頁(yè)面播放效果實(shí)例代碼,新版的音悅臺(tái) APP 播放頁(yè)面交互非常有意思,可以把播放器往下拖動(dòng),然后在底部懸浮一個(gè)小框,還可以左右拖動(dòng)。2017-01-01
RecyclerView實(shí)現(xiàn)側(cè)滑和網(wǎng)絡(luò)斷點(diǎn)續(xù)傳
這篇文章主要為大家詳細(xì)介紹了RecyclerView實(shí)現(xiàn)側(cè)滑和網(wǎng)絡(luò)斷點(diǎn)續(xù)傳,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-07-07
Android5.0+ CollapsingToolbarLayout使用詳解
這篇文章主要為大家詳細(xì)介紹了Android5.0+ CollapsingToolbarLayout使用,感興趣的小伙伴們可以參考一下2016-09-09
Android 調(diào)用系統(tǒng)應(yīng)用的方法總結(jié)
這篇文章主要介紹了Android 調(diào)用系統(tǒng)應(yīng)用的方法總結(jié)的相關(guān)資料,這里提供調(diào)用錄像,錄音,拍照等功能,需要的朋友可以參考下2017-08-08

