【发布时间】:2019-11-28 10:17:27
【问题描述】:
我已将我的项目迁移到 AndroidX。我的MainActivity 扩展FragmentActivity 我的第一个SwitchCompat 看起来全是白色的,当我第一次来到那个屏幕时它根本没有任何颜色。 SwitchCompat is white。它下面的所有其他 SwitchCompact 都具有正确的颜色。如果我按下返回并再次回到那个屏幕,我的第一个 SwitchCompact 会收到正确的颜色并且看起来很好。
如果我更改我的MainActivty 扩展AppCompactActivity,那么当我第一次到达该屏幕时一切正常。有谁知道这里哪里有问题,因为在迁移之前我的MainActivity 也扩展了FragmentActivity,一切都很好。
我的xml 代码在这两种情况下都是一样的:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".BlankFragment">
<androidx.appcompat.widget.SwitchCompat
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<androidx.appcompat.widget.SwitchCompat
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
【问题讨论】:
-
你能提供你的布局代码吗?
-
嗨,迪米特里。问题不在代码中。代码是一样的。但是当我的 MianActivity 扩展 AppCompcatActivity 行为很好,但如果我扩展 FragmentActivity 则行为就像我描述的那样。布局中的代码始终相同。
-
同样的事情发生在我身上。问题来自 Theme.AppCompat.DayNight 主题
标签: android androidx switchcompat