Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/184.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何使绿色成功/红色失败屏幕褪色?_Android_Android Layout - Fatal编程技术网

Android 如何使绿色成功/红色失败屏幕褪色?

Android 如何使绿色成功/红色失败屏幕褪色?,android,android-layout,Android,Android Layout,所以我有了一个非常基本的测试应用程序,它调用了一个API,并且得到了一个50/50的响应,不管是成功还是失败。我只有一个调用API按钮,当我点击它时,我想让应用程序淡入一个绿色屏幕,屏幕上显示一条类似“成功”的文字!然后在那里停留5秒钟,如果它失败了,它会做类似的事情,只是一个红色的Fail 到目前为止,我只得到了一个简单的主视图,如下所示: <?xml version="1.0" encoding="utf-8"?> <layout xmlns:android="http:/

所以我有了一个非常基本的测试应用程序,它调用了一个API,并且得到了一个50/50的响应,不管是成功还是失败。我只有一个调用API按钮,当我点击它时,我想让应用程序淡入一个绿色屏幕,屏幕上显示一条类似“成功”的文字!然后在那里停留5秒钟,如果它失败了,它会做类似的事情,只是一个红色的Fail

到目前为止,我只得到了一个简单的主视图,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<layout 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">

<androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/mainContainer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/white">

<TextView
            android:id="@+id/testApiLabel"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="100dp"
            android:layout_marginTop="4dp"
            android:layout_marginEnd="100dp"
            android:layout_marginBottom="4dp"
            android:text="Click the button to test API"
            android:textAlignment="center"
            android:textColor="@color/black"
            android:textSize="20sp"
            app:layout_constraintBottom_toTopOf="@id/testApiButton"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.4" />

        <Button
            android:id="@+id/testApiButton"
            style="@style/DefaultButton"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="100dp"
            android:layout_marginEnd="100dp"
            android:onClick="@{() -> view.onCallAPI()}"
            android:text="Test API"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.95" />

    </androidx.constraintlayout.widget.ConstraintLayout>
</layout>

我怎样才能生成这个代码?希望我的要求有道理。我想做一个DialogFragment,但我不确定这是一个很好的方法。

我最终在同一个视图中创建了3个约束布局,当我从API获得响应时,我使用此代码进行更改

private fun startAnimationOfNewView(view: ConstraintLayout) {
        val cx = view.width / 2
        val cy = view.height / 2

        val finalRadius = hypot(cx.toDouble(), cy.toDouble()).toFloat()
        val anim =
            ViewAnimationUtils.createCircularReveal(view, cx, cy, 0f, finalRadius)
        view.visibility = View.VISIBLE
        anim.start()
    } 

其他视图一开始是不可见的,这很好。几秒钟后,我又换回来了

你熟悉安卓系统的编码吗?是的,我只是出于某种原因对此感到茫然你需要使用使图像停留5秒。我更关注的是如何使用一些文本使屏幕变为绿色,比如UI,因为我将不使用处理程序的东西,而是看看是否可以使用kotlin的方式。对于全屏,请看一看。您可以创建一个单独的活动,仅显示颜色和文本,并在5秒钟后完成