android - 如何使 View 始终位于最前面?

标签 android always-on-top android-background

我有一个 TextView,它在一张图片上。当我点击按钮时,TextView 的背景颜色会改变,但图像不会消失。例如:

我的TextView开头:

enter image description here

当我点击一个按钮时:

enter image description here

最佳答案

如果您只想使用一个 TextView 来做到这一点,那么这可能是不可能的。因此,我建议您使用 FrameLayout 来完成此操作。你可以像下面这样写你的布局。

<FrameLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#FFFFFF" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="" />

</FrameLayout>

当您想更改 TextView 背后的颜色时,请更改 ImageView 背景,如下所示...

ImageView mageView view = (ImageView) findViewById(R.id.image);
view.setBackgroundColor(Color.BLUE);

关于android - 如何使 View 始终位于最前面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22089080/

相关文章:

android - 如何使 Activity 窗口始终保持在顶部

javascript - 如何让窗口保持在最上面

android - 是否可以将android应用程序的背景制作成gif之类的动画背景?

android - 如何知道应用程序何时从后台删除?

java - 如何检查 gson 的 int 字段是否为空? [安卓]

android - 应用 WebView 中的 OTP 检测

android - 在少数 Activity 中显示操作栏

c++ - 在Linux上使用QT,有没有办法禁用 "Always on Top"?

php - 所有 GCM 参数?

android - 在AsyncTask和IntentService之间进行选择的决定因素是什么?