androidalways-on-topandroid-background

How to make a view as always on top?


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


Solution

  • 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);