效果图:
1.在lib中添加Jar包(badgeview.jar)并在build中添加
//添加badgeview框架
implementation files('libs/badgeview.jar')
2.xml布局
<LinearLayout 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"
android:gravity="center_horizontal"
android:orientation="vertical" >
<TextView
android:id="@+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="hello_world" />
<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="Button" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:src="@mipmap/ic_launcher" />
<LinearLayout
android:id="@+id/layout1"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginTop="20dp"
android:background="#E0EEE0"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
3.Activity调用
package com.ruidde.pictureselectordemo;
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.Gravity;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.jauker.widget.BadgeView;
public class MainActivity extends Activity {
private Context mContext;
private TextView textView;
private Button btn;
private ImageView imageView;
private LinearLayout layout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mContext = this;
initData();
}
private void initData() {
textView = (TextView) findViewById(R.id.tv1);
btn = (Button) findViewById(R.id.btn1);
imageView = (ImageView) findViewById(R.id.imageView1);
layout = (LinearLayout) findViewById(R.id.layout1);
BadgeView badgeView = new com.jauker.widget.BadgeView(this);
badgeView.setTargetView(textView);
badgeView.setBadgeCount(3);
badgeView = new BadgeView(this);
badgeView.setTargetView(btn);
badgeView.setBadgeCount(-7);
// 图片貌似不能使用badgeview
badgeView = new BadgeView(this);
badgeView.setTargetView(imageView);
badgeView.setBadgeCount(0);
badgeView = new BadgeView(this);
badgeView.setTargetView(layout);
badgeView.setBackground(12, Color.parseColor("#9b2eef"));
badgeView.setText("提示");
badgeView = new BadgeView(this);
badgeView.setTargetView(layout);
badgeView.setBadgeGravity(Gravity.BOTTOM | Gravity.CENTER);
badgeView.setBadgeCount(4);
badgeView = new BadgeView(this);
badgeView.setTargetView(layout);
badgeView.setBadgeGravity(Gravity.CENTER);
badgeView.setBackgroundColor(Color.RED); //在设置背景颜色 ,不设置倒角时,背景为矩形(如果不设置背景颜色,默认是圆形且颜色是橘红色)
badgeView.setBadgeMargin(-1); // 设置显示位置距上下左右的距离
badgeView.setTextColor(Color.BLACK);
badgeView.setBadgeCount(10);
badgeView = new BadgeView(this);
badgeView.setTargetView(layout); //设置哪个控件显示数字提醒,参数就是一个view对象
badgeView.setBadgeGravity(Gravity.LEFT | Gravity.CENTER);// 设置badgeview的显示位置
badgeView.setBackground(20, Color.RED); //第一个参数:背景圆的倒角 ,第二个参数:背景圆的颜色
badgeView.setTextColor(Color.BLACK); //设置提醒的数字的字体颜色
badgeView.setBadgeCount(-6); //设置提醒的数字
badgeView = new BadgeView(this);
badgeView.setTargetView(layout);
badgeView.setBadgeGravity(Gravity.TOP | Gravity.LEFT);
badgeView.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.ITALIC)); // 设置显示的字体
badgeView.setShadowLayer(2, -1, -1, Color.GREEN); // 设置字体的阴影
badgeView.setBadgeMargin(5); // 设置显示位置距上下左右的距离
badgeView.setBadgeCount(2);
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/119207.html