Android 从styles.xml切换应用程序主题时,是否有方法更改项目的可见性?

Android 从styles.xml切换应用程序主题时,是否有方法更改项目的可见性?,android,android-theme,android-styles,Android,Android Theme,Android Styles,我试图实现一种效果,根据所选的应用程序主题,这个星空背景动画可见/消失 <com.starry.animation android:id="@+id/stars" android:layout_width="match_parent" android:layout_height="match_parent" app:starsView_bigStarThreshold="10dp" app:starsView_

我试图实现一种效果,根据所选的应用程序主题,这个星空背景动画可见/消失

<com.starry.animation
        android:id="@+id/stars"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:starsView_bigStarThreshold="10dp"
        app:starsView_meteoritesColors="@array/meteorites_colors"
        app:starsView_meteoritesEnabled="true"
        app:starsView_meteoritesInterval="2000"
        app:starsView_maxStarSize="3dp"
        app:starsView_minStarSize="1dp"
        android:visibility="?visibilityMode"
        android:background="@android:color/transparent"
        app:starsView_starColors="@array/star_colors_small"
        app:starsView_starCount="100" />

我已将styles.xml中的visibilityMode声明为字符串属性

<attr name="visibilityMode" format="string" />

在我的自定义主题中:

<item name="visibilityMode">GONE</item>
消失了

这会导致错误的星图膨胀。是否有其他实现可以实现类似的结果?

实际上可见性不是一个字符串,而是一个整数。
0
用于可见的初始状态。
2
用于初始状态
(不要与
View.Gone
View.Visible
混淆)

因此,在您的情况下,自定义属性可能如下所示:

<attr name="visibilityMode" format="integer">
  <!-- Visible on screen; the default value. -->
    <enum name="visible" value="0" />
    <!-- Completely hidden, as if the view had not been added. -->
    <enum name="gone" value="2" />
</atrr>

实际上可见性不是一个字符串,而是一个整数。
0
用于可见的初始状态。
2
用于初始状态
(不要与
View.Gone
View.Visible
混淆)

因此,在您的情况下,自定义属性可能如下所示:

<attr name="visibilityMode" format="integer">
  <!-- Visible on screen; the default value. -->
    <enum name="visible" value="0" />
    <!-- Completely hidden, as if the view had not been added. -->
    <enum name="gone" value="2" />
</atrr>

谢谢,成功了!只需要将int改为integer,然后用instead@TBoneEpclan太好了)我找到了答案谢谢,成功了!只需要将int改为integer,然后用instead@TBoneEpclan太好了)我确定了答案