Android BGABadgeView:显示提示数字(2)
在附录文章3的基础上,对代码进行稍微改造,显示在红色小圆球内部显示数字,同时给红色小圆球通过可编程调控红色小圆球的整体外观,布局文件和附录文章3类似。主要是Java代码:
package zhangphil.demo; import android.graphics.Color; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import cn.bingoogolapple.badgeview.BGABadgeTextView; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final BGABadgeTextView badgeTextView = (BGABadgeTextView) findViewById(R.id.text); badgeTextView.showCirclePointBadge(); //初始化 badgeTextView.showTextBadge("9"); badgeTextView.getBadgeViewHelper().setBadgeTextSizeSp(15); badgeTextView.getBadgeViewHelper().setBadgeTextColorInt(Color.WHITE); badgeTextView.getBadgeViewHelper().setBadgeBgColorInt(Color.RED); badgeTextView.getBadgeViewHelper().setDragable(true); badgeTextView.getBadgeViewHelper().setBadgePaddingDp(6); badgeTextView.getBadgeViewHelper().setBadgeBorderWidthDp(2); badgeTextView.getBadgeViewHelper().setBadgeBorderColorInt(Color.WHITE); findViewById(R.id.button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (badgeTextView.isShowBadge()) badgeTextView.hiddenBadge(); else { badgeTextView.showCirclePointBadge(); //注意带上这个显示数字,否则将变成空 badgeTextView.showTextBadge("99+"); } } }); } }
代码运行结果:
附录文章:
1,《仿微信、短信、QQ等消息数目右上角红色小圆球气泡显示(基于Android XML布局文件实现)》链接地址:http://blog.csdn.net/zhangphil/article/details/43702953
2,《仿短信条目右上角的红色小圆球提示气泡》链接地址:http://blog.csdn.net/zhangphil/article/details/43667727
3,《Android BGABadgeView:新消息/未接来电/未读消息/新通知圆球红点提示(1)》链接地址:http://blog.csdn.net/zhangphil/article/details/51822514