Tag: 覆盖

启动覆盖活动,而不显示应用程序的其余部分

我目前有一个应用程序组成的多个活动,其中之一是一个半透明的。 该应用程序有通知,当我点击它时,我希望它打开半透明的活动在任何目前在屏幕上。 到目前为止,如果我的应用程序已关闭,则可以使用,但如果正在运行,并且覆盖活动打开,则我的应用程序的其余部分也处于前台。 我想这样做,只有叠加在那里,一旦用户按回来,它会回到他们原来的应用程序。 这种模仿谷歌浏览器的标签活动。 我正在通过PendingIntent启动我的活动: val intent = Intent(context, WebOverlayActivity::class.java) //intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP or PendingIntent.FLAG_ONE_SHOT) intent.putExtra(ARG_URL, …) intent.action = System.currentTimeMillis().toString() //dummy action val bundle = ActivityOptionsCompat.makeCustomAnimation(context, R.anim.slide_in_right, R.anim.slide_out_right).toBundle() val pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_ONE_SHOT, bundle) 这些标志是我在其他地方开展活动时所拥有的标志,但是它们似乎并没有影响到这个待定的意图。 如上所述,这项活动是半透明的,并吸引了其他的活动。 我感觉这就涉及到将这个活动与其他应用程序任务分开,但是我也在应用程序中使用了叠加层,我不确定这是否会影响到任何内容。 有任何想法吗? 编辑1:这是活动清单 <activity android:name=".WebOverlayActivity" android:theme="@style/AppTheme.Overlay"> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> […]

检测覆盖中的触摸事件并进一步传递

我想做一个overlay手势检测器,将显示在所有其他应用程序之上。 覆盖将从Service启动。 我已经做了示例服务,只是为了检查触摸覆盖图标的触摸事件是否可以以某种方式记录并进一步调度到当前活动的应用程序: class GestureDetectorService : Service() { override fun onBind(intent: Intent?): IBinder? = null val windowManager: WindowManager get() = getSystemService(Context.WINDOW_SERVICE) as WindowManager var iv: AppCompatImageView? = null override fun onCreate() { super.onCreate() iv = AppCompatImageView(this) iv?.setImageResource(R.drawable.icon) iv?.setOnTouchListener { view, motionEvent -> when (motionEvent.action) { MotionEvent.ACTION_DOWN -> { Log.d("Click", "From icon") false } else -> […]

Kotlin:覆盖子类型中的泛型属性

我试图写一些通用的代码,但不能摆脱Type of 'PROPERTY' is not a subtype of the overridden property错误Type of 'PROPERTY' is not a subtype of the overridden property 。 我的代码简化版本: abstract class BaseP<V> { var view: V? = null } abstract class BaseF { fun smth() { pp.view = this } abstract val pp: BaseP<BaseF> } abstract class SubF: BaseF() { abstract […]

Kotlin覆盖成员设置并获取

有没有人知道更好的方式来听取自己的基类内的成员变化? class FOO { val t: String } class BOO: FOO { fun x(val t: String) { // notify when t was changed } } 在我看来,与观察员JavaRx会很多。 科特林代表不能继承工作(或者我找不到方法)。 我想出的最好的是在“BOO”中覆盖“t”的setter和getter。 但是这个有点尴尬,因为这个“为什么我应该覆盖一个成员?” 或者“为什么我只需要定义一个集合,然后得到什么时候我只需要设置?” 所以我的解决方案: import kotlin.properties.Delegates fun main(args: Array<String>) { var foo = FOO() foo.t = "foo" foo.printT() var boo = BOO() boo.t = "boo" boo.printT() } open […]

在Kotlin中泛型的子类型问题

我在我的代码中有以下继承模式。 trait A { fun foo(): Set<A> } trait B : A { override fun foo(): MutableSet<B> } trait C : A { override fun foo(): Set<C> } trait D : C, B { override fun foo(): MutableSet<D> } 当B和D返回集合时,编译器能够确定Set<D>是Set<B>和Set<C>的子类型。 但是,当我将B.foo和D.foo的返回类型更改为MutableSet ,编译器能够验证B.foo的返回类型,但是我得到一个错误,报告D.foo的返回类型不是子类型的MutableSet<B> 。 为什么科特林无法推断这种形式的亚型,有没有工作,而没有检修我的等级?

在kotlin中覆盖泛型的功能

例如,我有以下示例代码 fun f<T>( cb: (T, Int) -> Unit ): Unit { println("f called with cb which accepts 2 arguments"); } fun f<T>( cb: (T) -> Unit ): Unit { println("f called with cb which accepts 1 argument"); f<T> {item, position -> cb(item) } } fun main(args : Array<String>) { f { item -> } f […]

Kotlin数据类实现Java接口

我正在尝试将Kotlin引入到我目前的项目中。 我决定从实体开始,这些实体似乎完美地映射到数据类。 比如我有一个数据类: data class Video(val id: Long, val ownerId: Long, val title: String, val description: String? = null, val imgLink: String? = null, val created: Date? = null, val accessKey: String? = null, val views: Long? = null, val comments: Long? = null, val videoLink: String? = null): Entity 其中实现了Java接口: public interface Entity { […]