0
我有一个按钮小部件,出现在多个布局。最终在最终版本中,该按钮对用户是隐藏的,但在此之前,我需要它可以在开发的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>"
/>
另一种办法是有一个布尔值,并以编程设置按钮的知名度,但它必须在每一个活动做这个按钮,在它的布局。
嗯......你确定字串资源这里是正确的方法吗?通常,这些都需要是整数资源,数字值是符号名称的基础。 – CommonsWare
我刚刚测试过它,它似乎工作(至少在布局编辑器中)。使用各个常量的值创建一个int资源也可能会起作用。 – Miraduro
我得到'java.lang.NumberFormatException:Invalid int:'gone''在'setContentView(R.layout.my_layout)'行;' – rraallvv