Skip to content Skip to sidebar Skip to footer

Textview On(above) Button, Doesn't Work In Android 5(api 21)

It looks like a bug in 5 Android(API 21). I need a textview on button, textview should placed above the button. It works correct on Android 4.1(API 16) and incorrect on 5 Android(A

Solution 1:

Yes. It is big chnage in Android L(API 21). There is new thing - Elevation, it is something like z-index in HTML. So to fix this bug you need use android:elevation="100dp" OR android:translationZ="100dip" for view that should be on top. So correct code is:

<?xml version="1.0" encoding="utf-8"?><RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/rlBottom"android:layout_width="fill_parent"android:layout_height="match_parent" ><FrameLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentLeft="true"android:background="#00FF00"><Buttonandroid:id="@+id/bVio"android:layout_width="wrap_content"android:layout_height="50dip"android:text="VIO"></Button><TextViewandroid:id="@+id/bVio_count"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="00"android:textSize="12dip"android:textColor="#FFFFFF"android:background="@drawable/rounded_textbox"android:elevation="100dp"/></FrameLayout></RelativeLayout>

Solution 2:

You need to wrap your button in a layout separately from the TextView, I used FrameLayout to wrap it and make sure your TextView is under the button's layout and it should work.

Post a Comment for "Textview On(above) Button, Doesn't Work In Android 5(api 21)"