Сервис должен раздувать макет, чтобы отображать его как плавающий виджет. Я могу заразиться нематериальными компонентами пользовательского интерфейса. Но когда я использую компоненты материала, такие как кнопка, приложение вылетает со следующей ошибкой.
java.lang.RuntimeException: Unable to create service com.example.WindowService: android.view.InflateException: Binary XML file line #82: Binary XML file line #82: Error inflating class com.google.android.material.button.MaterialButton
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3740)
at android.app.ActivityThread.access$1400(ActivityThread.java:235)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1784)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:6981)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1445)
Caused by: android.view.InflateException: Binary XML file line #82: Binary XML file line #82: Error inflating class com.google.android.material.button.MaterialButton
Caused by: android.view.InflateException: Binary XML file line #82: Error inflating class com.google.android.material.button.MaterialButton
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.view.View.inflate(View.java:26170)
at com.example.WindowService.onCreate(WindowService.kt:29)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3728)
at android.app.ActivityThread.access$1400(ActivityThread.java:235)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1784)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:6981)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1445)
Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).
at com.google.android.material.internal.ThemeEnforcement.checkTheme(ThemeEnforcement.java:240)
at com.google.android.material.internal.ThemeEnforcement.checkMaterialTheme(ThemeEnforcement.java:215)
at com.google.android.material.internal.ThemeEnforcement.checkCompatibleTheme(ThemeEnforcement.java:143)
at com.google.android.material.internal.ThemeEnforcement.obtainStyledAttributes(ThemeEnforcement.java:78)
at com.google.android.material.button.MaterialButton.<init>(MaterialButton.java:200)
at com.google.android.material.button.MaterialButton.<init>(MaterialButton.java:191)
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.view.View.inflate(View.java:26170)
at com.example.WindowService.onCreate(WindowService.kt:29)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3728)
at android.app.ActivityThread.access$1400(ActivityThread.java:235)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1784)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:6981)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1445)
Внутреннее обслуживание onCreate. Строка выбрасывает над ошибкой.
floatingView = View.inflate(this, R.layout.floating_view, null)
Floating_layout содержит ConstraintLayout с привязкой данных и под виджетом материала.
<com.google.android.material.button.MaterialButton
android:id="@+id/material_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/device_name"/>
Я пытался изменить AppTheme на несколько доступных тем материала для тега <application>
, но проблема все еще та же.