Android仿Iphone通知角标的实现

来源:互联网 发布:json测试工具 编辑:程序博客网 时间:2024/06/07 16:06
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
packagecc.testtipmessage2;
importcom.readystatesoftware.viewbadger.BadgeView;
importandroid.os.Bundle;
importandroid.widget.ImageView;
importandroid.app.Activity;
importandroid.graphics.Color;
/**
 * Demo描述:
 * 仿Iphone通知角标的实现,借以提示用户有几条新的信息
 *
 * 参考资料:
 *https://github.com/jgilfelt/android-viewbadger
 *http://blog.csdn.net/t12x3456/article/details/9337555
 * Thank you very much
 */
publicclass MainActivity extendsActivity {
     privateImageView mImageView;
    @Override
    protectedvoid onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        init();
    }
    privatevoid init(){
        mImageView=(ImageView) findViewById(R.id.imageView);
        BadgeView badgeView = newBadgeView(MainActivity.this, mImageView);
        badgeView.setText("5");
        badgeView.setTextSize(8.5f);
        badgeView.setTextColor(Color.DKGRAY);
        badgeView.show();
    }
     
}
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<RelativeLayoutxmlns: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"
    >
 
    <ImageView
        android:id="@+id/imageView"
        android:layout_width="100dip"
        android:layout_height="100dip"
        android:background="@drawable/ic_launcher"
        android:layout_centerInParent="true"
   />
 
</RelativeLayout>
0 0