NoticeBar-网络异常等提示Bar
<h4>NoticeBar 组件</h4>
<h5>基本介绍</h5>
<p>1.在xml中定义</p>
<pre><code> <com.hongshi.employee.view.NoticeBar
android:id="@+id/notice_bar"
android:layout_width="match_parent"
android:layout_height="35dp"
android:background="@color/tips_bg_color"
android:paddingVertical="5dp"
app:leftIcon="@mipmap/close_orange"//左侧图标
app:leftText="@string/notice_open_notification_text"//左侧文字
app:leftTextSize="14sp"//左侧字体大小
app:leftTextColor="@color/tips_right_text_color"//左侧文字颜色
app:rightIcon="@mipmap/login_num"//右侧图标
app:rightText="@string/ok"//右侧文字
app:rightTextColor="@color/tips_right_text_color"//右侧字体颜色
app:rightTextSize="14sp"//右侧字体大小
app:rightTextStyle="LINE"//右侧文字样式 NORMAL:正常模式 LINE:带下划线
app:textMarginLeft="5dp"//左侧文字距离左侧
app:textMarginRight="20dp" />//左侧文字距离右侧</code></pre>
<p>2.组件中提供的方法(可链式调用)</p>
<pre><code>setLeftImageBackground(int) //左侧图标
setRightImageBackground(int) //右侧图标
setLeftText(int / string)//左侧文字
setRightText(int / string)//右侧文字
setLeftTextColor(int)//左侧文字颜色
setRightTextColor(int)//右侧文字颜色
setLeftIconClickListener(listener)//左侧图标点击事件
setRightIconClickListener(listener)//右侧图标点击事件
setRightTextClickListener(listener)//右侧文字点击事件
show();//只处理显示,文案内容需要在外部定义;
show(int type)//显示 传入type 内部使用了默认的处理文案的方式
dismiss()//隐藏</code></pre>
<h5>组件中定义了默认的几种交互状态</h5>
<pre><code> public enum NoticeBarType {
/**
* 网络异常
*/
NET_ERROR(-1, "当前网络不可用,请检查网络", ""),
/**
* WIFI网络
*/
NET_WIFI(1, "", ""),
/**
* 移动网络
*/
NET_MOBILE(2, "", ""),
/**
* 消息通知
*/
NOTIFICATION(3, "请打开系统通知,以便及时收到最新消息", "去开启"),
/**
* App更新
*/
APP_UPDATE(4, "有新版本,点击更新", "去更新");
public int type;//类型
public String title;//左侧文字
public String des;//右侧文字
NoticeBarType(int type, String title, String des) {
this.type = type;
this.title = title;
this.des = des;
}
}</code></pre>
<h5>具体使用</h5>
<ol>
<li>xml定义(同上)</li>
<li>在需要使用到的地方根据状态类型处理;(具体使用根据自己在业务中去处理具体的细节)
<pre><code>/**
* 处理网络变化的NoticeBar
* @param type 状态类型
*/
public void netStateChange(int type) {
NoticeBar noticeBar = mPageBinding.getRoot().findViewById(R.id.notice_bar);
if (noticeBar == null) return;
if (type == 3) {//消息通知被关闭提示
noticeBar.setLeftText(R.string.notice_open_notification_text)
.setRightText(R.string.notice_right_text)
.show();
} else if (type == -1) {
//当前网络不可用提示
noticeBar.setLeftText(R.string.notice_net_work_error)
.setRightText("")
.show();
}else {
noticeBar.dismiss();
}
}</code></pre>
<h5>效果</h5>
<p><img src="https://www.showdoc.cc/server/api/common/visitfile/sign/be1663ee5a2a2d49300d9a8c2fc37cdb?showdoc=.jpg" alt="" /></p></li>
</ol>