需求:
底部栏有通知或者未读消息时显示红点或者数字红点
效果图:
底部数字.png思路:
其实没什么难点,就写布局,红点用ImageView,数字红点用TextView。
只不过ImageView的src用的是点9图
关键代码:
就一个xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".modules.main.activity.MainActivity">
<FrameLayout
android:id="@+id/fl_content"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@id/ll_main_tab"/>
<LinearLayout
android:id="@+id/ll_main_tab"
android:layout_width="match_parent"
android:layout_height="@dimen/d98px"
android:background="@color/bg_15171a"
android:gravity="center"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent">
<RadioGroup
android:id="@+id/rg_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:paddingTop="@dimen/d12px">
<FrameLayout
android:id="@+id/fl_home"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<RadioButton
android:id="@+id/rb_home"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:button="@null"
android:checked="true"
android:drawableTop="@drawable/formal_main_home_button"
android:gravity="center"
android:text="首页"
android:textColor="@drawable/formal_main_nav_text_color"
android:textSize="@dimen/s20px" />
<TextView
android:id="@+id/tv_home_red"
android:layout_width="wrap_content"
android:layout_height="@dimen/d32px"
android:includeFontPadding="false"
android:paddingLeft="@dimen/d10px"
android:paddingRight="@dimen/d10px"
android:background="@drawable/aliwx_unread_hint"
android:gravity="center"
android:layout_gravity="right"
android:layout_marginRight="@dimen/d32px"
android:textColor="@android:color/white"
android:textSize="@dimen/s20px"
android:visibility="gone"
tools:visibility="visible"
android:text="0" />
</FrameLayout>
<FrameLayout
android:id="@+id/fl_discovery"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<RadioButton
android:id="@+id/rb_discovery"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:button="@null"
android:drawableTop="@drawable/formal_main_discovery_button"
android:gravity="center"
android:text="@string/discovery"
android:textColor="@drawable/formal_main_nav_text_color"
android:textSize="@dimen/s20px" />
</FrameLayout>
<FrameLayout
android:id="@+id/fl_mood"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<RadioButton
android:id="@+id/rb_mood"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:button="@null"
android:drawableTop="@drawable/formal_main_mood_button"
android:gravity="center"
android:text="@string/mood"
android:textColor="@drawable/formal_main_nav_text_color"
android:textSize="@dimen/s20px" />
<!--红点-->
<ImageView
android:id="@+id/iv_mood_red"
android:layout_width="@dimen/d18px"
android:layout_height="@dimen/d18px"
android:layout_gravity="right"
android:layout_marginBottom="@dimen/d10px"
android:layout_marginRight="20dp"
android:scaleType="centerCrop"
android:src="@drawable/aliwx_unread_hint"
android:visibility="gone" />
</FrameLayout>
<FrameLayout
android:id="@+id/fl_message"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<RadioButton
android:id="@+id/rb_message"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:button="@null"
android:drawableTop="@drawable/formal_main_message_button"
android:gravity="center"
android:text="@string/message"
android:textColor="@drawable/formal_main_nav_text_color"
android:textSize="@dimen/s20px" />
<!--数字红点-->
<TextView
android:id="@+id/tv_msg_unread_count"
android:layout_width="wrap_content"
android:layout_height="@dimen/d32px"
android:includeFontPadding="false"
android:paddingLeft="@dimen/d10px"
android:paddingRight="@dimen/d10px"
android:background="@drawable/aliwx_unread_hint"
android:gravity="center"
android:layout_gravity="right"
android:layout_marginRight="@dimen/d32px"
android:textColor="@android:color/white"
android:textSize="@dimen/s20px"
android:visibility="gone"
tools:visibility="visible"
tools:text="99" />
</FrameLayout>
<FrameLayout
android:id="@+id/fl_me"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<RadioButton
android:id="@+id/rb_me"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:button="@null"
android:drawableTop="@drawable/formal_main_me_button"
android:gravity="center"
android:text="@string/me"
android:textColor="@drawable/formal_main_nav_text_color"
android:textSize="@dimen/s20px" />
<ImageView
android:id="@+id/iv_red_me"
android:layout_width="@dimen/d18px"
android:layout_height="@dimen/d18px"
android:layout_gravity="right"
android:layout_marginBottom="@dimen/d10px"
android:layout_marginRight="20dp"
android:scaleType="centerCrop"
android:src="@drawable/aliwx_unread_hint"
android:visibility="gone"/>
</FrameLayout>
</RadioGroup>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
网友评论