![](/img/trans.png)
[英]Android | Change theme of TextInputLayout using styles.xml
[英]Is there a way to change visibility of an item when switching app theme from styles.xml?
我正在嘗試實現這種星空背景 animation 可見/消失的效果,具體取決於所選的應用程序主題。
<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>
這會導致星星視圖膨脹錯誤。 還有其他一些實現我可以達到類似的結果嗎?
實際上可見性不是一個字符串,而是一個 integer。
0
用於可見的初始 state。
2
用於消失的初始 state
(不要與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"
請查看這個答案
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.