How to set background opacity of a textview placed on to of ImageView

落花浮王杯 提交于 2019-12-05 04:54:30

In your TextView definition, add:

android:background="#8888"

888 being a mid grey (888888), with 8 being a mid alpha (88)

OR

android:background="#8000"

000 being a black (000000), with 8 being a mid alpha (88)

vipul mittal

You can set background color through xml as shown in other answers.

Also dynamically you can getBackgtound and set alpha.

textItem.getBackground().setAlpha(100); // int value between 0 and 255

Add the background property to your text view like this:

<TextView
android:id="@+id/textItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_alignBottom="@+id/iconItem"
android:paddingBottom="5dip"
android:textSize="10sp"
android:textColor="#FFF"
android:background="#70000000"/>
Jagadesh Seeram

Add android:background to the textView

<TextView
  android:id="@+id/textItem"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_centerHorizontal="true"
  android:layout_centerVertical="true"
  android:layout_alignBottom="@+id/iconItem"
  android:background="#80000000"
  android:paddingBottom="5dip"
  android:textSize="10sp"
  android:textColor="#FFF"/>

And you can change the Transparency according to the percentage

Check this understanding the Color codes in android

<FrameLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:orientation="vertical"
 android:padding="5dp">

<ImageView
android:id="@+id/iconItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/shout_ic"/>
 <TextView
android:id="@+id/textItem"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_alignBottom="@+id/iconItem"
android:paddingBottom="5dip"
android:textSize="10sp"
android:textColor="#FFF"/>
</FrameLayout>

Try adding

android:alpha="0.5"

to the TextView, it should make it semi transparent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!