package cc.testtipmessage2;import com.readystatesoftware.viewbadger.BadgeView;import android.os.Bundle;import android.widget.ImageView;import android.app.Activity;import android.graphics.Color;/** * Demo描述: * 仿Iphone通知角標的實現,藉以提示使用者有幾條新的資訊 * * 參考資料: * https://github.com/jgilfelt/android-viewbadger * http://blog.csdn.net/t12x3456/article/details/9337555 * Thank you very much */public class MainActivity extends Activity { private ImageView mImageView;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);init();} private void init(){ mImageView=(ImageView) findViewById(R.id.imageView); BadgeView badgeView = new BadgeView(MainActivity.this, mImageView);badgeView.setText("5");badgeView.setTextSize(8.5f);badgeView.setTextColor(Color.DKGRAY);badgeView.show();}}
<RelativeLayout 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" > <ImageView android:id="@+id/imageView" android:layout_width="100dip" android:layout_height="100dip" android:background="@drawable/ic_launcher" android:layout_centerInParent="true" /></RelativeLayout>