J'ai besoin de définir dynamiquement un fond d'image d'un textview et le rendre semi-transparent, avec du texte avec une opacité complète.Comment rendre l'arrière-plan de l'image de textview semi transparent mais pas le texte?
Quelque chose comme ça, mais compatible avec < 21 API.
android:backgroundTint="#80FFFFFF"
android:backgroundTintMode="src_over"
Lorsque j'utilise
textView.setBackgroundResource(x.getPicture());
textview.getBackground().setAlpha(80);
cela fonctionne, mais plus tard, quand j'utilise la même ressource à un imageview il reste transparent même si j'utilise
imageView.setImageAlpha(255);
ou
imageView.setAlpha((float) 1.0);
Et cela affecte tout te xtview y compris le texte lui-même.
textView.setAlpha((float) 0.5);
J'ai essayé tout ce que j'ai pu trouver mais je n'ai pas trouvé de solution. Qu'est-ce que je fais mal?
mise en page entier xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg1">
<include
android:id="@+id/top_toolbar_details"
layout="@layout/toolbar"
android:layout_width="0dp"
android:layout_height="68dp"
app:layout_constraintTop_toTopOf="parent"
tools:layout_editor_absoluteX="0dp" />
<LinearLayout
android:id="@+id/ll_graphics"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:orientation="vertical"
app:layout_constraintBottom_toTopOf="@+id/linearLayout"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/top_toolbar_details">
<!--This is the imageview-->
<ImageView
android:id="@+id/iv_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:keepScreenOn="true"
android:longClickable="true"
android:scaleType="centerInside"
app:layout_constraintBottom_toTopOf="@+id/linearLayout"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/top_toolbar_details" />
<VideoView
android:id="@+id/vv_video"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="@+id/iv_image"
app:layout_constraintBottom_toTopOf="@+id/linearLayout"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/top_toolbar_details"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0" />
<ScrollView
android:id="@+id/sv_scroller"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:scrollbars="vertical">
<!--This is the textview-->
<TextView
android:id="@+id/tv_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="20"
android:paddingBottom="20dp"
android:paddingEnd="20dp"
android:paddingStart="20dp"
android:paddingTop="10dp"
android:scrollbars="vertical"
android:textColor="@color/black"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="@+id/iv_image"
app:layout_constraintBottom_toTopOf="@+id/linearLayout"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/top_toolbar_details" />
</ScrollView>
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="5dp"
android:orientation="horizontal"
android:weightSum="1"
app:layout_constraintBottom_toTopOf="@+id/llImg"
app:layout_constraintHorizontal_bias="0.505"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent">
<ImageButton
android:id="@+id/b_last_viewed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:background="@drawable/circle_shape_drawable"
android:scaleType="fitCenter"
android:src="@drawable/ic_previous"
app:layout_constraintBottom_toTopOf="@+id/llImg"
app:layout_constraintHorizontal_bias="0.773"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/b_to_all"
app:layout_constraintTop_toBottomOf="@+id/vv_video"
app:layout_constraintVertical_bias="0.97" />
<ImageButton
android:id="@+id/b_to_all"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="20dp"
android:layout_marginStart="20dp"
android:adjustViewBounds="true"
android:background="@drawable/circle_shape_drawable"
android:scaleType="fitCenter"
android:src="@drawable/ic_grid"
app:layout_constraintBottom_toTopOf="@+id/llImg"
app:layout_constraintTop_toBottomOf="@+id/vv_video"
app:layout_constraintVertical_bias="0.95"
tools:layout_editor_absoluteX="176dp" />
<ImageButton
android:id="@+id/b_to_favourites"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:background="@drawable/circle_shape_drawable"
android:scaleType="fitCenter"
android:src="@drawable/ic_favourite"
app:layout_constraintBottom_toTopOf="@+id/llImg"
app:layout_constraintHorizontal_bias="0.164"
app:layout_constraintLeft_toRightOf="@+id/b_to_all"
app:layout_constraintRight_toRightOf="parent" />
</LinearLayout>
<LinearLayout
android:id="@+id/llImg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
tools:layout_editor_absoluteX="0dp">
<android.support.v17.leanback.widget.HorizontalGridView
android:id="@+id/gv_small_preview"
android:layout_width="wrap_content"
android:layout_height="80dp"
android:layout_marginBottom="0dp"
android:layout_marginTop="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/b_last_viewed"
app:layout_constraintVertical_bias="0.0"
tools:layout_editor_absoluteX="0dp" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
Essayez d'abord setAlpha sur l'image, puis réglez-le sur fond –