【问题标题】:How to create in Android a head bubble like in Viber (or something like facebook meesenger has)?如何在 Android 中创建一个像 Viber 一样的头部气泡(或者像 facebook meesenger 那样的东西)?
【发布时间】:2023-03-08 06:50:01
【问题描述】:

我已经创建了在 28 岁之前可以在旧 API 上完美运行的 head bubble。 在最新的 API 29 上,我无法从后台打开 Tap 应用程序。

这是头部气泡截图

Screenshot of head bubble when an app is in background

这是我当前的代码...

override fun onCreate() {
      super.onCreate()
      mCallHeadView = 
      LayoutInflater.from(this).inflate(R.layout.call_head, null);
      var params: WindowManager.LayoutParams = WindowManager.LayoutParams(
         WindowManager.LayoutParams.WRAP_CONTENT,
         WindowManager.LayoutParams.WRAP_CONTENT,
         LayoutParams.TYPE_APPLICATION_OVERLAY,
         WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
         PixelFormat.TRANSLUCENT
      )
      //val params = LayoutParams(LayoutParams.WRAP_CONTENT, 
     LayoutParams.WRAP_CONTENT, LayoutParams.TYPE_PHONE, 
     LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSLUCENT)
      params.gravity = Gravity.TOP or  Gravity.END
      params.x = 0
      params.y = 270

      mWindowManager = getSystemService(WINDOW_SERVICE) as? WindowManager;
      if( mWindowManager != null){
         mWindowManager!!.addView(mCallHeadView, params);
      }
      var closeButton = mCallHeadView!!.findViewById<ConstraintLayout> . 
      (R.id.callHead)
      closeButton.setOnClickListener {
         val i = Intent()
         i.setClass(this,MainActivity::class.java)
         i.flags = Intent.FLAG_ACTIVITY_NEW_TASK
         startActivity(i)
         stopSelf()

      }

【问题讨论】:

    标签: android android-service facebook-messenger viber


    【解决方案1】:

    因为在新版本的 Android(28 或更高版本)中实现 Bubbles 有所不同
    所以请尝试关注Android Documentation 或任何新教程,如this

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-11-17
      • 1970-01-01
      • 2010-12-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多