How to make TextView Text Transparent [Android]


To make a TextView text look transparent we need to set the android:alpha attribute to it.

It has a range of 0-1,

If you set android:alpha ="0.1" the text will be 90% transparent, whereas

If you set android:alpha ="0.9" the text will appear 10% transparent (i.e. almost opaque)

You can set alpha manually in XML view, or by simply using the Properties window in the design view of Android Studio (or eclipse equivalent)

Setting alpha property
Setting alpha property
<TextView
   android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:alpha="0.7"
    android:text="@string/hello_world" />

✏️ Note that the alpha attribute is available from API level 11 and higher, so if you are using minSDK levels below level then you won't get any error but the application will simply ignore this attribute and you will not be able to see the effect.




Recent Posts:




Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and Software Developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include Learnings, Video Tutorials, Code Snippets, How Tos, Blogs, Articles, etc.