I'm trying to put a TextView over a Button inside toolbar to show notification count. I have embedded the two into a FrameLayout, which SHOULD respect Z-order, but the TextView continues to be hidden, even if I add .bringToFront() in the code. Here is my layout (I removed unnecessary attributes and elements):
<android.support.v7.widget.Toolbar
android:id="@+id/bottom_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="center"
android:layout_alignParentBottom="true"
android:gravity="center"
android:padding="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center">
<Button
...
/>
<FrameLayout
android:layout_width="68dp"
android:layout_height="wrap_content">
<Button
android:layout_width="68dp"
android:layout_height="wrap_content"
android:text="Chats"
android:gravity="bottom|center"
android:textColor="#FFFFFF"
android:background="?attr/colorPrimary"
android:drawableTop="@drawable/ic_question_answer_white_24dp"
android:id="@+id/buttonChats"
android:textSize="10dp" />
<TextView
android:id="@+id/badgeView"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_gravity="top|right"
android:layout_marginRight="2dp"
android:background="#af2e00"
android:gravity="center"
android:textColor="#FFFFFF"
android:textSize="12sp"
android:textStyle="bold"
android:text="16" />
</FrameLayout>
</LinearLayout>
My suspect is that this attribute:
android:drawableTop="@drawable/ic_question_answer_white_24dp"
is being rendered after and covers the TextView. Any Hints will be really appreciated.
Solved! I had to add this attribute to TextView:
android:elevation="100dp"
Weird Android! :/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.