Android 仿微信的底部按钮的红色提示

方法一:更换RadioButton的背景图片。(只能实现红色的提示点,不能实现数字提醒)

RadioButton rb_new_1 = (RadioButton) findViewById(R.id.rb_new_1);
Drawable drawable = getResources().getDrawable(R.drawable.bottom_1_selector);
rb_new_1.setCompoundDrawablesWithIntrinsicBounds(null, drawable, null, null);

方法二:在RadioButton上添加一层TextView,显示数字背景为红色图片。(能实现数字提醒)

效果图,如图所示:


在布局文件中,进行设置

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background_img"
    android:clipToPadding="true"
    android:fitsSystemWindows="true"
    android:orientation="vertical" >

    <!-- <include layout="@layout/title_bar_small" /> -->

    <com.fengtai.customview.NoScrollViewPager
        android:id="@+id/view_pager"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@+id/rl_bottom"
        android:layout_gravity="center"
        android:flipInterval="30"
        android:persistentDrawingCache="animation" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="58dp"
        android:layout_alignParentBottom="true"
        android:background="#151f2a" >
    </LinearLayout>

    <RelativeLayout
        android:id="@+id/rl_bottom"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" >

        <RadioGroup
            android:id="@+id/radio_group"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <RadioButton
                android:id="@+id/rb_new_1"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:button="@null"
                android:drawablePadding="3dp"
                android:drawableTop="@drawable/bottom_1_selector"
                android:gravity="center"
                android:paddingBottom="6dp"
                android:text="我的工单"
                android:checked="true"
                android:textColor="@drawable/bottom_text_selector"
                android:textSize="13sp" />

            <RadioButton
                android:id="@+id/rb_new_2"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:button="@null"
                android:drawablePadding="3dp"
                android:drawableTop="@drawable/bottom_home_selector"
                android:gravity="center"
                android:paddingBottom="6dp"
                android:text="我的绩效"
                android:textColor="@drawable/bottom_text_selector"
                android:textSize="13sp" />

            <RadioButton
                android:id="@+id/rb_new_3"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:button="@null"
                android:drawablePadding="3dp"
                android:drawableTop="@drawable/bottom_paixun_selector"
                android:gravity="center"
                android:paddingBottom="6dp"
                android:text="培训考试"
                android:textColor="@drawable/bottom_text_selector"
                android:textSize="13sp" />

            <RadioButton
                android:id="@+id/rb_new_4"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:button="@null"
                android:drawablePadding="3dp"
                android:drawableTop="@drawable/bottom_jishi_selector"
                android:gravity="center"
                android:paddingBottom="6dp"
                android:text="即时通讯"
                android:textColor="@drawable/bottom_text_selector"
                android:textSize="13sp" />
        </RadioGroup>
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/rl_bottom">

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:visibility="visible" >

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1" 
                android:orientation="horizontal"
                android:gravity="right">
                
                <TextView
                    android:id="@+id/tv_unread"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/red_point_1"
                    android:text="9"
                    android:gravity="center"
                    android:textColor="@color/white"
                    android:layout_marginRight="8dp"
                    android:textSize="12sp"/>
            </LinearLayout>

           <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1" 
                android:orientation="horizontal"
                android:gravity="right">
                <TextView android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/red_point_1"
                    android:text="9"
                    android:gravity="center"
                    android:textColor="@color/white"
                    android:textSize="12sp"/>
            </LinearLayout>

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1" 
                android:orientation="horizontal"
                android:gravity="right">
                <TextView android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/red_point_1"
                    android:text="9"
                    android:gravity="center"
                    android:textColor="@color/white"
                    android:textSize="12sp"/>
            </LinearLayout>

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1" 
                android:orientation="horizontal"
                android:gravity="right">
                <TextView android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/red_point_1"
                    android:text="9"
                    android:gravity="center"
                    android:textColor="@color/white"
                    android:textSize="12sp"/>
            </LinearLayout>
        </LinearLayout>
    </RelativeLayout>
</RelativeLayout>



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值