1

I would like to create a transparent activity on top of an existing one. It appears at the end of a quiz to show the user their score and congratulate them, and also has some buttons for navigation. The design is non-negotiable. I've looked at the following posts: How to display transparent activity on the another activity without removing previous activity How to make Translucent Activity How do I create a transparent Activity on Android? Whenever I tried adding a theme and putting it in my manifest, the following behaviour occured: I start the intent (I don't ever finish() the last activity), and the translucent activity slides over from the right and just has a grey background which may or may not be transparent(nothing behind it so I can't tell). I tried implementing a fade-in animation instead, and it wasn't transparent, leading me to believe it was never transparent when it was sliding in from the right. Lots of people are satisfied with the stack overflow answers that involved styles and manifest, but I am very frustrated because they don't work for me. Are those answers outdated or am I doing something wrong?

Here's the 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.support.v7.widget.CardView
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      app:cardBackgroundColor="#80000000"
      app:layout_constraintTop_toTopOf="parent">

    <ImageView
        android:id="@+id/stars"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:srcCompat="@drawable/challenge_complete_stars" />

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

      <TextView
          android:id="@+id/textView2"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_gravity="center_horizontal"
          android:layout_marginTop="200dp"
          android:fontFamily="@font/opensans_semibold"
          android:text="TextView"
          android:textColor="@color/normalWhite"
          android:textSize="16sp"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toTopOf="parent"/>

      <TextView
          android:id="@+id/textView3"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginTop="30dp"
          android:text="TextView"
          android:textColor="@color/normalWhite"
          android:textSize="50sp"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toBottomOf="@+id/textView2"/>

      <Button
          android:id="@+id/returntoLessonsButton"
          android:layout_width="0dp"
          android:layout_height="wrap_content"
          android:layout_marginBottom="8dp"
          android:layout_marginEnd="100dp"
          android:layout_marginStart="100dp"
          android:layout_marginTop="8dp"
          android:background="@color/goaSuccessGreen"
          android:text="Return to lessons"
          android:textAllCaps="false"
          android:textColor="@color/goaWhite"
          android:textStyle="bold"
          app:layout_constraintBottom_toBottomOf="parent"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintHorizontal_bias="0.0"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toBottomOf="@id/viewBadgeButton"
          app:layout_constraintVertical_bias="0.034"/>

      <Button
          android:id="@+id/viewBadgeButton"
          android:layout_width="0dp"
          android:layout_height="wrap_content"
          android:layout_marginEnd="100dp"
          android:layout_marginStart="100dp"
          android:layout_marginTop="152dp"
          android:background="@color/goaSuccessGreen"
          android:text="View badge in profile"
          android:textAllCaps="false"
          android:textColor="@color/goaWhite"
          android:textStyle="bold"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintHorizontal_bias="0.0"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toBottomOf="@+id/textView3"/>
    </android.support.constraint.ConstraintLayout>

  </android.support.v7.widget.CardView>

</android.support.constraint.ConstraintLayout>
kevinlinxc
  • 470
  • 5
  • 20
  • And you cant just use a Dialog that is full-screen? – Logan Aug 06 '19 at 22:41
  • @CartOfSwine I tried using Dialog as the parent in the style to no avail. Can I use an xml layout with a dialog? – kevinlinxc Aug 07 '19 at 00:11
  • Can you please [edit] your question to show us the styles you're trying, and how you're setting them, exactly? – Mike M. Aug 07 '19 at 02:34
  • You can use xml layout with dialog. Just `View view = View.inflate(context, R.layout.your_layout_xml, null);`, then `dialog.setView(view);` – Joey Chong Aug 07 '19 at 03:18
  • Or, may be you can use a fragment that visibility is gone, when you want to display score, set all the information then set visibility to visible? – Joey Chong Aug 07 '19 at 03:21
  • @kevinlinxc you bet you can use an xml layout on a Dialog. Just make your xml and set the content view in the onCreate() of the dialog the same way you would in an activity. – Logan Aug 07 '19 at 16:28
  • The Dialog worked perfectly. Thanks everyone. – kevinlinxc Aug 08 '19 at 22:56

0 Answers0