Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is visibility in XML? dimen, string, etc (Android)

I want to have different visibility for each version (JB, KK and L). Then, I have some attr.xml files for each version, before I was using dimen value to set its height to 0 or X dpi, but now I need to remove the view.

What is visibility? is not a dimen, is not a string... how can I get it from my attr to my view with android:visibility="@XXXXXXX/myViewVisibility"

With the height I use android:visibility="@dimen/myViewHeight" and it works perfectly...

Thanks in advance.

like image 257
JavierSegoviaCordoba Avatar asked Oct 28 '25 09:10

JavierSegoviaCordoba


1 Answers

It is an enum. You can find the definition for the enum in the framework's attrs.xml (line 2163).

You can use an integer reference if you really want to use a resource reference, but I don't recommend it in case (for whatever reason) those constants change in the future. For example:

<resources>
    <!-- 2 corresponds to "gone" -->
    <integer name="my_visibility">2</integer>
</resources>

<View
    visibility="@integer/my_visiblity" />

A style would also work for version-specific visibility, like so:

<style name="MyViewStyle">
    <item name="android:visibility">gone</item>
</style>

<View
    style="@style/MyViewStyle" />
like image 52
Bryan Herbst Avatar answered Oct 31 '25 01:10

Bryan Herbst



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!