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

TBone Ep氏族

我正在尝试实现一种效果,根据选择的应用程序主题,此星空背景动画可见/消失。

<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中将visibleMode声明为字符串属性

<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>

比它可以在主题中使用: <item name="visibilityMode">gone</item>

并在您的布局项目中: android:visibility="?visibilityMode"

请查看此答案

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章