【问题标题】:In Android Studio, text does not appear on top of an image在 Android Studio 中,文本不会出现在图像顶部
【发布时间】:2021-11-06 05:16:31
【问题描述】:

我在 Android Studio 上做一个小项目,我放了一张图片作为深蓝色背景。 我在这个深蓝色图形的顶部插入了白色文本,但字母中的白色仍然没有显示出来。 图形界面。看到我把颜色设置为白色,但它仍然没有出现。 请检查:

拜托,谁能帮忙 [1]:https://i.stack.imgur.com/iTtiS.png

XML 中的源代码: [2]:https://i.stack.imgur.com/u6AIU.png

请问,Android Studio 中图片顶部出现白色文字怎么办?

整个 XML 布局:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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"
    tools:context=".MainActivity">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="410dp"
        android:layout_height="250dp"
        android:color="@color/white"
        android:foreground="@drawable/home_bg"
        android:textSize="30dp"
        android:textStyle="bold"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <TextView
            android:id="@+id/textView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Encontre o seu próximo destino!"
            android:textColor="@android:color/white"
            android:textSize="20dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.32"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.233" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="176dp"
            android:layout_height="41dp"
            android:layout_marginBottom="64dp"
            android:text="Procurar Destinos"
            android:textColor="#FFFFFF"
            android:textColorHighlight="@color/white"
            android:textSize="20dp"
            android:textStyle="bold"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.324"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/textView"
            app:layout_constraintVertical_bias="0.742" />

    </androidx.constraintlayout.widget.ConstraintLayout>


</androidx.constraintlayout.widget.ConstraintLayout>

【问题讨论】:

  • 能否请您添加整个 xml 布局?
  • 当然!我现在写了这个:)

标签: java android xml android-studio android-layout


【解决方案1】:

好的,我认为问题在于您设置了约束布局的前景而不是背景。

试试这个:

 <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="410dp"
        android:layout_height="250dp"
        android:color="@color/white"
        android:background="@drawable/home_bg"
        android:textSize="30dp"
        android:textStyle="bold"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

【讨论】:

  • 完美!非常感谢:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-02
  • 2011-02-24
  • 1970-01-01
  • 1970-01-01
  • 2017-10-25
相关资源
最近更新 更多