How to make a view as always on top?

Utku Soytaş picture Utku Soytaş · Feb 28, 2014 · Viewed 7.6k times · Source

I have a TextView and it is on an image. When I click the button, TextView's background color will change, but image won't disappear. For example:

My TextView at the beginning:

enter image description here

When I click a button:

enter image description here

Answer

Hamid Shatu picture Hamid Shatu · Feb 28, 2014

If you want to do this using only one TextView then its may be not possible. So, I will suggest you to do this using FrameLayout. you can write your layout as below.

<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>

When you want to change the color behind the TextView then change the ImageView background as below...

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