我有一个按钮窗口小部件,该按钮在多个布局中出现。最终,在最终版本中,该按钮将被用户隐藏,但是直到那时,我需要在开发的alpha和beta阶段看到它。
是否有一种方法可以从唯一的资源值中控制该按钮的可见性?
类似的东西:
<!-- Feedback button -->
<Button
android:id="@+id/feedback"
style="@android:style/Widget.Button.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="@dimen/buttons_margin"
android:layout_marginLeft="@dimen/buttons_margin"
android:text="Feedback"
android:visibility="<some resource value>"
/>
一种替代方法是具有布尔值,并以编程方式设置按钮的可见性,但是必须在其布局中的每个按钮中进行。
是的,这是可能的:
android:visibility="@integer/show_view"
和您的integers.xml
-File:
<integer name="show_view">0</string>
可能的值是
0 (VISIBLE)
1 (INVISIBLE)
2 (GONE)
在Miraduro的答案上构建构建,您可以为所有View
可见性选项添加integers.xml
条目:
<!-- View visibilities -->
<integer name="visible">0</integer>
<integer name="invisible">1</integer>
<integer name="gone">2</integer>
然后像这样引用它们:
<integer name="visibility_user_profile_item">@integer/visible</integer>
这将使其他团队成员更容易理解您在做什么。