Github 好用分享Android FloatWindow
1.導入Library
build.gradle: Project
allprojects {
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }
}
}
build.gradle: Module
dependencies {
implementation 'com.github.yhaolpz:FloatWindow:1.0.9'
}
2.創建MyApplication
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
val imageView = ImageView(this)
imageView.setImageResource(R.drawable.girl)
FloatWindow.with(this)
.setView(imageView)
.setWidth(Screen.width, 0.5f) //设置悬浮控件宽高
.setHeight(Screen.height, 0.5f)
.setX(Screen.width, 0.3f)
.setY(Screen.height, 0.3f)
.setMoveStyle(500, BounceInterpolator())
.setDesktopShow(true)
.build()
}
}
3.增加權限 & 註冊Application name
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<application
android:name=".MyApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.GitTest">
<activity
android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
4.效果展示