Android仿Iphone通知角标的实现(一)

时间:2022-05-08 04:46:09

MainActivity如下:

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;
@Override
protected 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();
}

}


 

main.xml如下:

<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>